Json字符串转换为List for windows phone 8

时间:2015-04-21 14:01:24

标签: windows-phone-8

[  
   {  
      "TotalCount":5,
      "purchaseStatus":"0",
      "inviteCount":0,
      "status":"success",
      "statusCode":"200",
      "message":"success",
      "user":[  
         {  
            "id":"ac789045e3f109f536e8c217e4e78fe6",
            "firstname":"Srinivasan",
            "lastname":"CP",
            "emailid":"seenu4689@gmail.com",
            "prof_image_path":"http:\/\/gps-dev.gpsmobitrack.com\/pickzy_dev\/upload\/img_2015-04-11-09-04-43.png",
            "gcm_regid":"NULL",
            "ios_device_id":"",
            "longitude":"80.245255",
            "latitude":"13.035394",
            "relationship":"Friend",
            "track_userid":"361",
            "date":"2015-04-18",
            "time":"13:08"
         },
         {  
            "id":"7ca84ee8cc024e3cf2f0736f89dc4ece",
            "firstname":"srini",
            "lastname":"cp",
            "emailid":"srinipickzy3@gmail.com",
            "prof_image_path":"http:\/\/gps-dev.gpsmobitrack.com\/pickzy_dev\/upload\/img_2015-04-11-08-04-41.png",
            "gcm_regid":"",
            "ios_device_id":"",
            "longitude":"80.245255",
            "latitude":"13.035394",
            "relationship":"Friend",
            "track_userid":"365",
            "date":"2015-04-21",
            "time":"19:26"
         },
         {  
            "id":"ef5b4c49b893c55ec77428b2c265510e",
            "firstname":"Naveen",
            "lastname":"Kumar",
            "emailid":"naveen.kumar@pickzy.com",
            "prof_image_path":"http:\/\/gps-dev.gpsmobitrack.com\/pickzy_dev\/upload\/img_2015-04-11-08-04-51.png",
            "gcm_regid":"NULL",
            "ios_device_id":"fbe87350c14ccbccc1ec4ad90986faa9c1124273ed9fb7708965c83a06dd7c32",
            "longitude":"80.245392",
            "latitude":"13.035848",
            "relationship":"Brother",
            "track_userid":"367",
            "date":"2015-04-10",
            "time":"17:45"
         },
         {  
            "id":"e6050d8b5d378cbc791ebab1295dd301",
            "firstname":"Parthiban",
            "lastname":"V M",
            "emailid":"parthibanemi@gmail.com",
            "prof_image_path":"http:\/\/gps-dev.gpsmobitrack.com\/pickzy_dev\/upload\/img_2015-03-28-07-03-52.png",
            "gcm_regid":"NULL",
            "ios_device_id":"",
            "longitude":"0.000000",
            "latitude":"0.000000",
            "relationship":"Friend",
            "track_userid":"368",
            "date":"2015-04-21",
            "time":"01:13"
         },
         {  
            "id":"9848d03341103f52816bf4d5a1e5467c",
            "firstname":"Naveen kumar",
            "lastname":"kumar",
            "emailid":"naveenkumar3506@gmail.com",
            "prof_image_path":"http:\/\/gps-dev.gpsmobitrack.com\/pickzy_dev\/upload\/img_2015-04-11-02-04-01.png",
            "gcm_regid":"NULL",
            "ios_device_id":"da8ef3258c4fbc42085ab1dcb62c7b6a4bd60112bb5507284a7a8b3958808c43",
            "longitude":"80.244835",
            "latitude":"13.035032",
            "relationship":"Other",
            "track_userid":"370",
            "date":"2015-04-18",
            "time":"19:38"
         }
      ]
   }
]

3 个答案:

答案 0 :(得分:1)

首先创建数据类,您可以使用json2csharp为您创建它们。然后使用NuGet添加引用Json.Net

然后你需要这样的东西:

JsonConvert.DeserializeObject<RootObject>(YourJson)

答案 1 :(得分:1)

使用Json2Csharp网站将您的json字符串转换为模型类。

您的Json数据的模型类将是这样的:

public class User
{
    public string id { get; set; }
    public string firstname { get; set; }
    public string lastname { get; set; }
    public string emailid { get; set; }
    public string prof_image_path { get; set; }
    public string gcm_regid { get; set; }
    public string ios_device_id { get; set; }
    public string longitude { get; set; }
    public string latitude { get; set; }
    public string relationship { get; set; }
    public string track_userid { get; set; }
    public string date { get; set; }
    public string time { get; set; }
}

public class RootObject
{
    public int TotalCount { get; set; }
    public string purchaseStatus { get; set; }
    public int inviteCount { get; set; }
    public string status { get; set; }
    public string statusCode { get; set; }
    public string message { get; set; }
    public List<User> user { get; set; }
}

之后,正如@hans Olsson所说,使用Json.Net Nu-Get包来将json字符串反序列化为你刚从Json2Csharp网站获得的模型类。

JsonConvert.DeserializeObject<RootObject>("") // your json data as string in the parameter.

答案 2 :(得分:0)

为您研究的一些方向。

3个步骤

  • 将json作为字符串
  • 将json解析为对象
  • 将对象绑定到列表

将json作为字符串

将你的json放入一个字符串中。你要下载吗?寻找这个。

将json解析为对象

构建对象的体系结构。你的json中包含哪些东西?您可以使用Visual Studio来帮助我们使用像json2csharp这样的工具。现在,您必须反序列化。 您可以使用像Json.NET这样的库来为您完成工作。我让你调查一下。

将对象绑定到列表

为了确定,你要一个列表框?