Click here to Skip to main content
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 2:38am
Edited 3-Sep-12 2: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 458
1 OriginalGriff 344
2 George Jonsson 233
3 Animesh Datta 130
4 Shemeemsha RA 128
0 OriginalGriff 6,179
1 Sergey Alexandrovich Kryukov 5,616
2 CPallini 4,770
3 George Jonsson 3,400
4 Gihan Liyanage 2,522

Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2014
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