C # / WP7: working with a JSON object that includes an array of JSON objects

I am new to using JSON and JSON.net, and I am having problems with an array of JSON objects in a JSON object. I use JSON.net, as other examples that I saw make it straightforward.

I download the following JSON line from the Internet:

{"count":2,"data":[{"modifydate":12345,"key":"abcdef", "content":"test file 1"},{"modifydate":67891,"key":"ghjikl", "content":"test file 2"}]}

I know that it needs to be deserialized, and for this I need the JSON class that I wrote:

    public class NOTE
    {
        [JsonProperty(PropertyName = "count")]
        public int count { get; set; }

        [JsonProperty(PropertyName = "key")]
        public string key { get; set; }

        [JsonProperty(PropertyName = "modifydate")]
        public float modifydate { get; set; }

        [JsonProperty(PropertyName = "content")]
        public string modifydate { get; set; }

    }

So I deserialize it using:

NOTE note = JsonConvert.DeserializeObject<NOTE>(e.Result);

This works fine, since I can access the count property and read it in order, but everything in the data property I cannot. It seems to me that this is an array of JSON objects and its problems that I encountered, I would like to get a list of, say, all "key" values ​​or all lines of "content".

, , , , , , .

- , :)

+3
1

JSON , , , . :

public class Note
{
    [JsonProperty(PropertyName = "count")]
    public int Count { get; set; }

    [JsonProperty(PropertyName = "data")]
    public Data[] Data { get; set; }
}

public class Data
{
    [JsonProperty(PropertyName = "modifydate")]
    public float ModifyDate { get; set; }

    [JsonProperty(PropertyName = "key")]
    public string Key { get; set; }

    [JsonProperty(PropertyName = "content")]
    public string Content { get; set; }
}

:

var note = JsonConvert.DeserializeObject<Note>(e.Result);
// loop through the Data elements and show content

foreach(var data in note.Data)
{
    Console.WriteLine(data.content);
}
+3

All Articles