我试图将字符串的多个部分作为我的项目的新字符串“它是fql的一部分”,我有这个字符串示例:
{"data": [{"text":"how can you get in"},{"text": "this is amazing..."},{"text": "this is another example"}, {"text":"let, this one be the last example and thanks you..."}]}
我想获得新字符串:
how can you get in this is amazing this is another example let this one be the last example and thanks you
另一个例子:
{"data": [{"text":"how can you get in"}]}
新字符串:
how can you get in
另一个:
{"data": []}
新字符串:此字符串的新字符串应为空。
注意:以上示例可以是任何大小和任何长度。
谢谢。答案 0 :(得分:2)
使用Json.Net
var anon = new { data = new[] { new { text = "" } } };
var obj = JsonConvert.DeserializeAnonymousType(json, anon);
var text = String.Join(" ", obj.data.Select(x=>x.text));
或
var jobj = JObject.Parse(json);
var text = String.Join(" ", jobj["data"].Select(x=>x["text"]));