Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Dear Frd,

Here is my JSON format.
[
{
"id": 1,
"name": "_default",
"locations": [
{
"id": 1,
"name": "_default",
"resources": []
}
]
},
{
"id": 3,
"name": "HSR Branch",
"locations": [
{
"id": 6,
"name": "Loc1",
"resources": []
}
]
},
{
"id": 2,
"name": "Kalyan Nagar Branch",
"locations": []
}
]


How to read this json in Winform using json.net


Please Help Me i hope u should help me
Posted
Comments
Rajesh_DotNet 6-Jan-14 2:20am    
you just change the json data in my solution and check..it will give you the result..:)
nixonanand 6-Jan-14 10:06am    
Thank you very much i did it.

1 solution

Hi..,
I can give you a simple example for deserializing it.

Here is my simple sample code which would give you some idea about it.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    public class Product
    {
        public  string id { get; set; }
        public string name { get; set; }
        public List<Location> Location { get; set; }
    }
}


C#
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication4
{
    public class Location
    {
        public string id { get; set; }
        public string name { get; set; }
        public string resources { get; set; }
    }
}


C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using  Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace ConsoleApplication4
{
    class Program
    {
        static void Main(string[] args)
        {
            var jsonResponse = "[{'Id':'2','Name':'Watch','Location':[{'id':'4','name':'chandru',resources:'kesavan'}]},{'Id':'3','Name':'TV','Location':[{'id':'4','name':'chandru',resources:'kesavan'}]},{'Id':'4','Name':'kannan','Location':[{'id':'4','name':'chandru',resources:'kesavan'}]}]";
           
            var jsonlist = JsonConvert.DeserializeObject<List<Product>>(jsonResponse);
        }
    }
}



By doing this you can convert your json data to your comfortability.

I think this will solve your problem surely.

Have a great day!!!
 
Share this answer
 
v6

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900