Search code examples
c#jsonjson.netjson-deserialization

Deserialising JSON String with JSON object serialised in the string


I am trying to deserialise a JSON string

string filter = @"[{""property"":""Student_PK"",""value"":""1""}]";

My first step was to

JsonConvert.DeserializeObject<Dictionary<string, string>>(filter)

which didn't work. However, I added a class to deserialise the object.

public class filterObject
{
    [JsonProperty("property")]
    string property {get; set;}

    [JsonProperty("value")]
    Object value { get; set; }
}

Running the following also did not work

JsonConvert.DeserializeObject<filterObject>(filter)

In this scenario, I do not have control over the filter string since this is generated by Sencha.

How else can I deserialise this JSON string as well as accommodating multiple JSON objects(property value combination) returned in a single string.


Solution

  • Your root is an array of Objects and not an object.

    Try JsonConvert.DeserializeObject<Dictionary<string, string>[]>(filter)

    Or with the second approach it should be JsonConvert.DeserializeObject<filterObject[]>(filter)