DeserializeObject Json

时间:2015-08-20 06:57:18

标签: json serialization

我有以下json数据,我需要反序列化它。顺便说一句,我正在使用C#,我尝试了以下内容: C#

// the data has been assigned to json variable 
Result deserializedResult = JsonConvert.DeserializeObject<Result>(json);

结果类

    private String _id = String.Empty;
    private String[] _result = { };
    private String _error = String.Empty;
    public Result()
    {

    }
    public String id
    {
        get { return _id; }
        set { _id = value; }
    }
    public String[] result
    {
        get { return _result; }
        set { _result = value; }
    }
    public String error
    {
        get { return _error; }
        set { _error = value; }
    }

JSON

{"id":1,"result":
[
{"id":12345,
"list_id":54321,
"is_test":false,
"type":"manual",
"creator_name":"Test Solutions"
},
{"id":54321,
"list_id":12345,
"is_test":false,
"type":"manual",
"creator_name":"Test Solutions"
}
],
"error":null}

ERROR

Additional information: Error reading string. Unexpected token: StartObject. Path 'result[0]', line 1, position 19.

1 个答案:

答案 0 :(得分:0)

我错过了一些如此明显的东西。而不是另一个对象,结果类我期待一个数组。我修复了编辑Result属性chaning

的问题
public String[] result { get; set; }

public List<Result> result { get; set; }

谢谢,抱歉打扰。祝你有愉快的一天