[英]Dealing with a JSON object's property called “private” in C# with Newtonsoft's JSON.NET
我正在尝试解析从空气质量鸡蛋的混合饲料返回的json字符串。 其中一家酒店指出,混合饲料是公共的还是私人的。 该属性称为private
并采用字符串值“ true”或“ false”。 为了从提要中获取数据,我正在调用xively的Historical Data REST API,该API成功返回了我有效的JSON。 然后,我使用JSON.NET解析C#中的JSON。 我的解析因此开始:
dynamic historicalDatapoints = JValue.Parse(jsonString) as JObject;
if (historicalDatapoints != null)
{
var id = historicalDatapoints.id;
var title = historicalDatapoints.title.ToString();
var privacy = bool.Parse(historicalDatapoints.private.ToString())
// More parsing
}
我对最后一行代码有疑问。 C#不允许我引用称为“私有”的属性。 这是对应的(已编辑的)JSON:
{
"id": 000000843,
"title": "Blah Road Egg 02",
"private": "false",
//...
}
如何使用JSON.NET解析属性private
?
尝试historicalDatapoints.@private
访问该值。 如果这不起作用,那么您也可以尝试historicalDatapoints["private"]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.