Newtonsoft.Json,如何编码通用选择 [英] Newtonsoft.Json, How to code generic selection
本文介绍了Newtonsoft.Json,如何编码通用选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
进一步使用 Newtonsoft.Json,Path返回了多个令牌,
对于此代码:
JObject o = JObject.Parse(jsStr);
IEnumerable<JToken> selEnum = o.SelectTokens(theFilter);
其中jsStr
是).
where the jsStr
is the content of https://api.github.com/search/repositories?q=Newtonsoft.Json&sort=stars&order=desc, and theFilter
can be any valid JPATH query string (e.g., ".items"
or ".items[*].owner"
).
如何将所选内容作为有效的json字符串返回?
How to return the selected as a valid json string?
推荐答案
听起来您只需要Json.SerializeObject
:
var o = JObject.Parse(jsStr);
var selEnum = o.SelectTokens(theFilter);
var newJson = JsonConvert.SerializeObject(selEnum);
这将为您提供代表原始JSON中所有owner
值的数组的JSON.
This will give you JSON representing an array of all of the owner
values from the original JSON.
这篇关于Newtonsoft.Json,如何编码通用选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文