如何解析这个json字符串?我试着放入字典
var dictionary = text.FromJson<Dictionary<string, string>>();
但是数组没有被解析。
{"v":[[9,-1],[9,-44,1]]}
最佳答案
试试这门课
public class Root
{
public List<List<int>> v;
}
var result = text.FromJson<Root>();
编辑
由于你的json串变了,我用Json.Net准备了一个sample
string json = @"{ v: [ [ 9, 16929, 1, 856, 128, '123', 'hello', {'type': 'photo', 'attach1': '123_456'} ] ] } ";
var obj = (JObject)JsonConvert.DeserializeObject(json);
foreach (var arr in obj["v"])
{
foreach(var item in arr)
{
if (item is JValue)
{
Console.WriteLine(item);
}
else
{
Console.WriteLine(">>> " + item["type"]);
}
}
}
关于c# - 使用 ServiceStack 解析 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12052393/