我是json的新手。我必须在c#中使用linq到json查询过滤json数据。我必须从以下示例json数据中检索多个值:
{
"parts": [
{
"attributes": {
"Motherboard": "Gigabyte GA-H81M-S2H",
"Max RAM": "16GB",
"Form Factor": "Micro ATX",
"RAM Slots": 2,
"Socket / CPU": "LGA1150"
},
"type": "Motherboard",
"name": "Gigabyte GA-H81M-S2H",
"slug": "gigabyte-motherboard-gah81ms2h"
},
{
"attributes": {
"Motherboard": "MSI H55-G43",
"Max RAM": "16GB",
"Form Factor": "ATX",
"RAM Slots": 4,
"Socket / CPU": "LGA1156"
},
"type": "Motherboard",
"name": "MSI H55-G43",
"slug": "msi-motherboard-h55g43"
},
{
"url": "http://pcpartpicker.com/part/asus-motherboard-rampageivblackedition",
"attributes": {
"Motherboard": "Asus Rampage IV Black Edition",
"Max RAM": "128GB",
"Form Factor": "EATX",
"RAM Slots": 8,
"Socket / CPU": "LGA2011"
},
"type": "Motherboard",
"name": "Asus Rampage IV Black Edition",
"slug": "asus-motherboard-rampageivblackedition"
}
],
}
请帮助我查询如何使用where子句选择多个(键,值)。我必须使用where子句选择名称,段码,形状因子,主板。
首先需要创建与JSON
内容结构相关的类。这个免费的在线工具可以帮助您轻松地从JSON数据创建c#类。然后你需要将这个JSON解析为一个c#类的对象。
之后,您可以在此object
上执行LINQ
操作,过滤它们并根据需要解析回JSON
。
可以使用Json。. NET中所有序列化和反序列化操作。