简体   繁体   中英

Convert JSON-string to C# JsonObject

I am trying to develop a metro-style app using C# and XAML. In that app, I am getting some data in JSON-formatted string from a service. A sample is shown below:

  [{
    "displayFieldName" : "OBJECT_NAME", 
    "fieldAliases" : {
        "OBJECT_NAME" : "OBJECT_NAME", 
        "OBJECT_TYPE" : "OBJECT_TYPE"
    }, 
    "positionType" : "point", 
    "reference" : {
        "id" : 1111
    }, 
    "objects" : [ {
        "attributes" : {
            "OBJECT_NAME" : "test name", 
            "OBJECT_TYPE" : "test type"
        }, 
        "position" : {
            "x" : 5, 
            "y" : 7
        }
    } ]
}]

Actually I am getting the data as a single line, a very long line. Anyway, I want to process it in C# as a JSON-object. How can I do that, convert that string to a C# object?

您可以使用内置的json序列化器/反序列化器,也可以使用第三方工具,例如Json.NET。

I ran into this issue the other day.
I was able to parse it using JsonArray.Parse .

Another solution was to wrap the array in an object like this:

{ items: <original string here> }

Then you can use JsonObject.Parse to retrieve an object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM