c# - 使用 ServiceStack 解析 JSON

标签 c# json

如何解析这个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/

相关文章:

c# - 基于标签和地理位置的 Instagram 提要

json - 将 JSON 中的字符串(字符串数组)解析为 Swift 中的字符串数组

php - 使用 PHP 从 MYSQL 获取数据到 JSON

c# - C#中位图图像的灰度变暗问题

c# - Marshal.PtrToStructure 抛出 System.ArgumentException 错误

c# - 需要什么 Control.IsHandleCreated?

c# - 任务栏(explorer.exe)被杀死后重新打开它?

javascript - Json call&loop inside json call&loop with each

javascript - 在 json_encode 中传递 � 或 ü

c# - 不想 JSON 序列化整个类列表