0

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?

Abbas
  • 14,186
  • 6
  • 41
  • 72
Null Pointer
  • 9,089
  • 26
  • 73
  • 118
  • 1
    Possible duplicate: http://stackoverflow.com/questions/2859753/what-is-simpliest-c-sharp-function-to-parse-json-string-into-object – Abbas Mar 08 '12 at 08:48

2 Answers2

1

You can use inbuilt json serializer/Deserializer or use third party tools such as Json.NET.

Nayana Setty
  • 1,001
  • 1
  • 12
  • 34
0

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.

Jean
  • 7,623
  • 6
  • 43
  • 58
pseudomuto
  • 266
  • 4
  • 3