Consider the following JSON format:
<code class="language-json">{ "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 } } ] }</code>
To extract only the data in the "objects" array, you can use Json.net to deserialize JSON into .NET objects:
<code class="language-csharp">Foo foo = JsonConvert.DeserializeObject<Foo>(json);</code>
Define the following classes to match JSON structures:
<code class="language-csharp">public class NameTypePair { public string OBJECT_NAME { get; set; } public string OBJECT_TYPE { get; set; } } public class Position { public int x { get; set; } public int y { get; set; } } public class SubObject { public NameTypePair attributes { get; set; } public Position position { get; set; } } public class Foo { public List<SubObject> objects { get; set; } }</code>
After deserialization, you can access the data in the "objects" array using the foo.objects
attribute.
The above is the detailed content of How to Extract Data from a JSON Array Using Json.net?. For more information, please follow other related articles on the PHP Chinese website!