C#.NET如何反序列化JSON的复杂对象 [英] C# .net how to deserialize complex object of JSON

查看:272
本文介绍了C#.NET如何反序列化JSON的复杂对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSON字符串,我需要一些帮助来反序列化。

I have a JSON string and I need some help to deserialize it.

什么工作对我来说..这是JSON

nothing worked for me.. this is the JSON

{
"response": [
    {
     "loopa": "81ED1A646S894309CA1746FD6B57E5BB46EC18D1FAff",

     "drupa": "D4492C3CCE7D6F839B2BASD2F08577F89A27B4ff",

     "images": [

         {

         "report": {

         "nemo": "unknown"

    },

      "status": "rock",

      "id": "7e6ffe36e-8789e-4c235-87044-56378f08m30df",

      "market": 1

},

   {

"report": {

"nemo": "unknown"

},

"status": "rock",

"id": "e50e99df3-59563-45673-afj79e-e3f47504sb55e2",

"market": 1

   }

  ]

 }

]

}

我有类的例子,但我没有使用这些类,我不介意使用一些其他类。 这些都是类:

i have an example of the classes but i don't have to use those classes, i don't mind using some other classes. these are the classes:

public class Report
{
    public string nemo { get; set; }
}

public class Image
{
    public Report report { get; set; }
    public string status { get; set; }
    public string id { get; set; }
    public int market { get; set; }
}

public class Response
{
    public string loopa { get; set; }
    public string drupa{ get; set; }
    public Image[] images { get; set; }
}

public class RootObject
{
    public Response[] response { get; set; }
}

我想提一提,我有Newtonsoft.Json已经这样我就可以使用一些功能从那里。

I want to mention that i have Newtonsoft.Json already so i can use some functions from there.

我该怎么办呢? 谢谢。

how can I do this? thanks.

推荐答案

我使用这样的在我的code和它的正常工作

I am using like this in my code and it's working fine

下面是一张code,你需要写

below is a piece of code which you need to write

using System.Web.Script.Serialization;

JavaScriptSerializer oJS = new JavaScriptSerializer();
RootObject oRootObject = new RootObject();
oRootObject = oJS.Deserialize<RootObject>(Your JSon String);

这篇关于C#.NET如何反序列化JSON的复杂对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆