Click here to Skip to main content
11,489,549 members (76,289 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# JSON

I am getting dynamic json data form of nested multidimensional array data is dynamic so i cant define class and set the properties, now how can i get all keys and values of data in a proper format in c#.
Posted 3-Sep-12 3:38am
Edited 3-Sep-12 3:39am
CodeHawkz at 3-Sep-12 10:29am
How are we supposed to know what your 'proper format' is? :S Tell us how you want to the data to end up? E.g. In a Dictionary instance
aspnet_regiis at 3-Sep-12 12:14pm
'proper' is not a W3C compliant standard. So you cannot deserialize the JSON data to 'proper' format...
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Use fastJSON[^]'s Parse() method it will give you Dictionary<string,object> representation of the JSON which you can traverse.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

JavaScriptSerializer this is inbuilt class in .net framework

using System.Web.Script.Serialization;
public void Deserialize()
            JavaScriptSerializer js = new JavaScriptSerializer();
            string jScript = "{NAME:'SAMPLE', AGE:'00',INTEREST:'CODEPROJECT'}";
            EmployeeRecord emp = js.Deserialize<employeerecord>(jScript);
public class EmployeeRecord
        public string Name { get; set; }
        public int Age { get; set; }
        public string Interest { get; set; }
In case JSON is in array, use list to convert to c# objects

List< EmployeeRecord > sc = js.Deserialize<List< EmployeeRecord >>(jScript);

for more information MSDN

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 OriginalGriff 278
2 Maciej Los 180
3 _duDE_ 141
4 Frankie-C 135
0 Sergey Alexandrovich Kryukov 9,488
1 OriginalGriff 8,425
2 Sascha Lefèvre 3,344
3 Maciej Los 3,066
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100