我有这个JSON对象
{
"08f4f705-6e14-4781-8241-d04bf2dc6ada": {
"description": "xxxxxxxx",
"note": "yyyyyyyy"
},
"05f4f995-6e14-4567-8241-d04bf2d456ee": {
"description": "aaaaaa",
"note": "bbb"
},
"0675f995-6e14-4567-8241-d4567f2d456z": {
"description": "fffff",
"note": "gggg"
}
}
我需要转换成这样的JSON数组:(这些元素应该是第一级属性的内容)
[
{
"description": "xxxxxxxx",
"note": "yyyyyyyy"
},
{
"description": "aaaaaa",
"note": "bbb"
},
{
"description": "fffff",
"note": "gggg"
}
]
我无法操纵该对象,也没有找到适合的资源。我该怎么办?
您可以将json字符串反序列化为Dictionary<string, object>
:
var obj = JsonConvert.DeserializeObject<Dictionary<string, object>>(json);
之后,您提取值并将其序列化回json:
var newJson = JsonConvert.SerializeObject(obj.Values);