使用在字符串中序列化的 JSON 个对象反序列化 JSON 字符串

Deserialising JSON String with JSON object serialised in the string

我正在尝试反序列化一个 JSON 字符串

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

我的第一步是

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

没用。但是,我添加了一个 class 来反序列化对象。

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

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

运行以下也不行

JsonConvert.DeserializeObject<filterObject>(filter)

在这种情况下,我无法控制过滤器字符串,因为它是由 Sencha 生成的。

我还能如何反序列化此 JSON 字符串以及在单个字符串中返回多个 JSON 对象(属性 值组合)。

JSON数组格式的数据,所以用对象class的列表序列化Json,试试这个,

JsonConvert.DeserializeObject<List<filterObject>>(filter);

您的根是一个对象数组,而不是一个对象。

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

或者第二种方法应该是JsonConvert.DeserializeObject<filterObject[]>(filter)