且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在VB.NET Newtonsoft中解析Json列表

更新时间:2023-01-17 21:07:53

据我所知,有多种方法可以做到这一点,我更喜欢以下更简单,更直接,更易于维护的方法

As per as my knowledge there are multiple ways to do it, i prefer following way which is more easy ,straight and maintainable

.net框架中内置了JSON序列化器和反序列化器,为此,您必须创建将映射到JSON的类.您可以查看或 http://msdn.microsoft .com/en-us/library/system.web.script.serialization.javascriptserializer.deserialize.aspx

there is JSON serializer and deserializer provided inbuilt in .net framework, requirement for that is, you have to create classes which will map to your JSON. you can have a look at or http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.deserialize.aspx

在上述情况下,您必须像下面一样创建类

In the above case you have to create your class like below

class UserLatLang
{
public long lat { get;set;}
public long lng { get;set;}
public long user_id {get;set;}
public string user {get;set;} 
}

之后,您可以

var serializer = new JavaScriptSerializer();
var listofUserLatLang = serializer.Deserialize<UserLatLang>(responseText);

,您将在listofUserLatLang中获得UserLatLang的列表

and you will get a list of UserLatLang in listofUserLatLang

,或者您也可以从 http://msdn.microsoft.com/zh-CN/library/bb412179.aspx

一旦获得UserLatLang的列表,就可以直接将其绑定到DataGrid

Once you get list of UserLatLang you can directly bind it to DataGrid

希望这可以解决您的问题

Hope this solves your problem

谢谢, 桑德什·达迪(Sandesh Daddi)

thanks, Sandesh Daddi