include_ice
2020-09-25 13:04
采纳率: 100%
浏览 125

C#请问外部为方括号的json字符串怎么处理?

比如这种:
[
{"boss":"Mirumok Destroyer Offin","spawnat":"2020-09-25T04:52:48.397Z","channel":4,"hb":false,"wb":true,"icon":"of","warn10":true},
{"boss":"Nouver","spawnat":"2020-09-25T05:00:59.397Z","channel":2,"hb":false,"wb":true,"icon":"nv","warn10":true},
{"boss":"Dastard Bheg","spawnat":"2020-09-25T05:03:10.397Z","channel":3,"hb":false,"wb":false,"icon":"db"},
{"boss":"Nouver","spawnat":"2020-09-25T05:17:12.397Z","channel":3,"hb":false,"wb":true,"icon":"nv"}
]

找到一个相关文章,但是没看懂...
https://blog.csdn.net/cdefg198/article/details/7520398

已解决.

JavaScriptSerializer Serializer = new JavaScriptSerializer(); //创建转换对象

List objs = Serializer.Deserialize>(方括号的json字符串); //转换
foreach (var item in objs)
{
Console.WriteLine(item.boss); //输出验证
}
//下面该类的格式由json字符串决定.
public class c
{
public string boss { get; set; }
public string spawnat { get; set; }
public string channel { get; set; }
public string hb { get; set; }
public string wb { get; set; }
public string icon { get; set; }
}

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • threenewbee 2020-09-25 13:59
    已采纳

    方括号是数组,怕麻烦最外面再嵌套一层,用List 作为其中的属性

    class A
    {
    public List<c> a { get; set; }
    }
    
    "a":[
    {"boss":"Mirumok Destroyer Offin","spawnat":"2020-09-25T04:52:48.397Z","channel":4,"hb":false,"wb":true,"icon":"of","warn10":true},
    {"boss":"Nouver","spawnat":"2020-09-25T05:00:59.397Z","channel":2,"hb":false,"wb":true,"icon":"nv","warn10":true},
    {"boss":"Dastard Bheg","spawnat":"2020-09-25T05:03:10.397Z","channel":3,"hb":false,"wb":false,"icon":"db"},
    {"boss":"Nouver","spawnat":"2020-09-25T05:17:12.397Z","channel":3,"hb":false,"wb":true,"icon":"nv"}
    ]
    
    已采纳该答案
    打赏 评论

相关推荐 更多相似问题