如何使用Json.Net在WinForms中读取json [英] How Do I read json in WinForms Using Json.Net
问题描述
亲爱的Frd,
这是我的JSON格式。
[
{
id:1,
name:_ default,
locations:[
{
id:1,
name:_ default,
resources:[]
}
]
},
{
id:3,
名称:高铁分行,
地点:[
{
id:6,
名称:Loc1,
资源:[]
}
]
},
{
id:2,
name:Kalyan Nagar Branch,
位置:[]
}
]
如何使用json.net在Winform中读取这个json
请帮助我,我希望你能帮助我
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
推荐答案
嗨..,
我可以给你一个简单的反序列化示例。
这是我的简单示例代码,可以让你对它有所了解。
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.
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; }
}
}
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; }
}
}
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);
}
}
}
通过这样做你可以将您的json数据转换为您的舒适度。
我认为这肯定会解决您的问题。
祝你有美好的一天!!!
By doing this you can convert your json data to your comfortability.
I think this will solve your problem surely.
Have a great day!!!
这篇关于如何使用Json.Net在WinForms中读取json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!