使用 Linq Json 生成对象图查询?
我正在使用包含以下内容的 json 文件:
{
"objects":[
{"object": 1,
"data":{
"name": "object 1",
"priority_threshold": "6000",
"email_threshold": "2000"
}},
{"object": 3,
"data":{
"name": "object 3",
"priority_threshold": "5000",
"email_threshold": "2000"
}},
{"object": 5,
"data":{
"name": "object 5",
"priority_threshold": "5000",
"email_threshold": "1000"
}},
{"object": 6,
"data": {
"name": "object 6",
"priority_threshold": "4000",
"email_threshold": "2000"
}
}
]}
.json 文件是嵌入式文件,并且作为字符串返回。
然后,我使用 System.Web.Script.Serialization.JavaScriptSerializer 从字符串反序列化该对象,以执行以下操作:
Dictionary<string, object> toConfigGraph = (Dictionary<string, object> toSerializer.DeserializeObject(psJsonString);
object[] toEventServiceConfig = (object[])toConfigGraph["objects"];
遇到的问题是我只想使用对象 ID 返回特定对象的数据,但我不确定最佳流程。我想实现一个 Linq 解决方案,但到目前为止我什至不确定这是否可行,因为 toConfigGraph["applications"] 返回基于 json 结构的对象数组。
任何建议将不胜感激。
我宁愿不必遍历对象数组。
谢谢。
I'm working with a json file containing the following:
{
"objects":[
{"object": 1,
"data":{
"name": "object 1",
"priority_threshold": "6000",
"email_threshold": "2000"
}},
{"object": 3,
"data":{
"name": "object 3",
"priority_threshold": "5000",
"email_threshold": "2000"
}},
{"object": 5,
"data":{
"name": "object 5",
"priority_threshold": "5000",
"email_threshold": "1000"
}},
{"object": 6,
"data": {
"name": "object 6",
"priority_threshold": "4000",
"email_threshold": "2000"
}
}
]}
the .json file is an embedded file and is being returned as a string.
Then from the string I am deserializing the object using System.Web.Script.Serialization.JavaScriptSerializer to do the following:
Dictionary<string, object> toConfigGraph = (Dictionary<string, object> toSerializer.DeserializeObject(psJsonString);
object[] toEventServiceConfig = (object[])toConfigGraph["objects"];
The problem running into is that I only want to return the data for a particular object using the object ID, but I'm unsure as to the best process. The I would like to implement a Linq solution, but as of now I'm not even sure if that will work since toConfigGraph["applications"] returns an array of objects based on the structure of the json.
Any suggestions would be greatly appreciated.
I'd rather NOT have to iterate through the object array.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)