Reputation: 13
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.
Upvotes: 1
Views: 160
Reputation: 16
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)
Upvotes: 0
Reputation: 626
Data in the format of JSON array, So serialize Json with the List of the Object class, Try this one,
JsonConvert.DeserializeObject<List<filterObject>>(filter);
Upvotes: 1