簡體   English   中英

當值從int更改為array + order時如何序列化json可能會更改

[英]how to serialize json when the value changes from int to array + order may change

我不確定如何將以下示例從json序列化為ac#對象。 通常,我會執行以下操作:

 JavaScriptSerializer ser = new JavaScriptSerializer();
 result = ser.Deserialize<Library.Libraries.Model.Post>(responseFromServer);

但是在這種情況下,由於值和順序可能會更改,因此我不確定如何創建該類的基礎。

這是示例:

    {
       "data": [
          {
             "id": "0000000/insights/page_fan_adds_unique/day",
             "name": "page_fan_adds_unique",
             "period": "day",
             "values": [
                {
                   "value": 2,
                   "end_time": "2010-09-15T07:00:00+0000"
                },
                {
                   "value": 0,
                   "end_time": "2010-09-16T07:00:00+0000"
                },
                {
                   "value": 1,
                   "end_time": "2010-09-17T07:00:00+0000"
                }
             ],
             "description": "Daily New Likes of your Page (Unique Users)"
          },
          {
             "id": "0000000/insights/page_fan_adds/day",
             "name": "page_fan_adds",
             "period": "day",
             "values": [
                {
                   "value": 2,
                   "end_time": "2010-09-15T07:00:00+0000"
                },
                {
                   "value": 0,
                   "end_time": "2010-09-16T07:00:00+0000"
                },
                {
                   "value": 1,
                   "end_time": "2010-09-17T07:00:00+0000"
                }
             ],
             "description": "Daily New Likes of your Page (Total Count)"
          },
          {
             "id": "0000000/insights/page_fan_removes_unique/day",
             "name": "page_fan_removes_unique",
             "period": "day",
             "values": [
                {
                   "value": 0,
                   "end_time": "2010-09-15T07:00:00+0000"
                },
                {
                   "value": 1,
                   "end_time": "2010-09-16T07:00:00+0000"
                },
                {
                   "value": 0,
                   "end_time": "2010-09-17T07:00:00+0000"
                }
             ],
             "description": "Daily Unlikes of your Page (Unique Users)"
          },
          {
             "id": "0000000/insights/page_fan_removes/day",
             "name": "page_fan_removes",
             "period": "day",
             "values": [
                {
                   "value": 0,
                   "end_time": "2010-09-15T07:00:00+0000"
                },
                {
                   "value": 1,
                   "end_time": "2010-09-16T07:00:00+0000"
                },
                {
                   "value": 0,
                   "end_time": "2010-09-17T07:00:00+0000"
                }
             ],
             "description": "Daily Unlikes of your Page (Total Count)"
          },
          {
             "id": "0000000/insights/page_fan_adds_source_unique/day",
             "name": "page_fan_adds_source_unique",
             "period": "day",
             "values": [
                {
                   "value": {
                      "fan_box": 1,
                      "fan_page": 1
                   },
                   "end_time": "2010-09-15T07:00:00+0000"
                },
                {
                   "value": [

                   ],
                   "end_time": "2010-09-16T07:00:00+0000"
                },
                {
                   "value": {
                      "fan_page": 1
                   },
                   "end_time": "2010-09-17T07:00:00+0000"
                }
             ],
             "description": "Daily Users can like your page in many different places, both within Facebook and on other websites.  These are the most common places where users like your Page. (Unique Users)"
          },

問題是最后一個結果的值從

 "value": 0,

 "value": {
            "fan_box": 1,
            "fan_page": 1
          },

此外,返回的JSON的順序可能會更改...

因此,我不確定如何進行序列化……有人有什么建議嗎?

您要解析的JSON是對象

您的反序列化代碼將更改為

result = ser.Deserialize<List<Library.Libraries.Model.Post>>(responseFromServer);

關於有價值的東西,您可以共享Library.Libraries.Model.Post的類定義嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM