Click here to Skip to main content
12,888,493 members (51,473 online)
Rate this:
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
Updated 3-Sep-12 2:39am
CodeHawkz 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<string, object> instance
aspnet_regiis 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170424.1 | Last Updated 4 Sep 2012
Copyright © CodeProject, 1999-2017
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