1

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.

0

2 Answers 2

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Using this I could not retrieve the value of the keys property and value.
0

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)

1 Comment

I use JsonConvert.DeserializeObject<Dictionary<string, string>[]>(filter) I then added a .ToDictionary(c => c["property"], c => c["value"]) to convert this back into a Dictionary<string, string

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.