Json解析器与统一c#

时间:2017-04-20 01:36:38

标签: c# json parsing unity3d hololens

我如何使用Json,UWP& amp;来解析这个json uisng unity,c#。统一?任何帮助谢谢   在C#.NET中将JSON字符串解析为JSON对象

  {
    "items":[
    {
    "created":"2017-04-14T09:56:30.593Z",
    "createdBy":"12",
    "name":"2",
    "errorMessage":null,
    "errorRetry":0,
    "errorType":null,
    "id":44,
    "package":"12",
    "partner":"1",
    "reference":null,
    "release":{
    "category":null,
    "configType":null,
    "contributors":[
    ],
    "created":"1",
    "createdBy":null,
    "files":[
    ],
    "genre":null,
    "id":15,
    "isKeyRelease":false,
    "metadata":[
    ],
    "owner":null,
    "owningTerritoryCode":"Worldwide",
    "prices":[
    ],
    "reference":"111111",
    "resources":[
    ],
    "scheduling":[
    ],
    "scope":null,
    "status":"None",
    "title":"Test 3",
    "updated":"0001-01-01T00:00:00Z"
    },
    "releaseId":15,
    "scheduleDate":"2017-04-14T09:56:30.593Z",
    "status":"Processed",
    "step":"Complete",
    "type":"Insert",
    "updated":"2017-04-14T09:56:33.42Z"
    },

    ],
    "page":1,
    "pageCount":3,
    "pageSize":10,
    "totalCount":24
    }*

2 个答案:

答案 0 :(得分:1)

使用Json.Net回答:

var str =
    "{\r\n    \"items\":[\r\n    {\r\n    \"created\":\"2017-04-14T09:56:30.593Z\",\r\n    \"createdBy\":\"12\",\r\n    \"name\":\"2\",\r\n    \"errorMessage\":null,\r\n    \"errorRetry\":0,\r\n    \"errorType\":null,\r\n    \"id\":44,\r\n    \"package\":\"12\",\r\n    \"partner\":\"1\",\r\n    \"reference\":null,\r\n    \"release\":{\r\n    \"category\":null,\r\n    \"configType\":null,\r\n    \"contributors\":[\r\n    ],\r\n    \"created\":\"1\",\r\n    \"createdBy\":null,\r\n    \"files\":[\r\n    ],\r\n    \"genre\":null,\r\n    \"id\":15,\r\n    \"isKeyRelease\":false,\r\n    \"metadata\":[\r\n    ],\r\n    \"owner\":null,\r\n    \"owningTerritoryCode\":\"Worldwide\",\r\n    \"prices\":[\r\n    ],\r\n    \"reference\":\"111111\",\r\n    \"resources\":[\r\n    ],\r\n    \"scheduling\":[\r\n    ],\r\n    \"scope\":null,\r\n    \"status\":\"None\",\r\n    \"title\":\"Test 3\",\r\n    \"updated\":\"0001-01-01T00:00:00Z\"\r\n    },\r\n    \"releaseId\":15,\r\n    \"scheduleDate\":\"2017-04-14T09:56:30.593Z\",\r\n    \"status\":\"Processed\",\r\n    \"step\":\"Complete\",\r\n    \"type\":\"Insert\",\r\n    \"updated\":\"2017-04-14T09:56:33.42Z\"\r\n    }\r\n\r\n    ],\r\n    \"page\":1,\r\n    \"pageCount\":3,\r\n    \"pageSize\":10,\r\n    \"totalCount\":24\r\n    }";
var converter = JsonConvert.DeserializeObject<dynamic>(str);
Console.WriteLine(converter.totalCount); //Just a test: the result is 24!

答案 1 :(得分:0)

Unity提供了一个实用程序解析器,可以将Json转换为类

https://docs.unity3d.com/Manual/JSONSerialization.html