将复杂JSON解析为c#List [英] Parsing Complex JSON to c# List
问题描述
您好,
如何将json字符串解析为列表。我的json输出列表如下:
{
delivery_codes:[
{
postal_code :{
区:苏拉特,
pin:395001,
pre_paid:Y,
现金:Y,
提货:Y,
cod:Y,
is_oda:N,
state_code:GJ
}
},
{
postal_code:{
区:苏拉特,
pin:395009,
pre_paid:Y,
现金:Y,
提货:Y,
cod:Y,
is_oda:N,
state_code:GJ
}
}
]
}
我的班级结构是:
公共类postal_code_list
{
public String district {get;组; }
public String pin {get;组; } $ / $
public String pre_paid {get;组; }
public String cash {get;组; }
public String pickup {get;组; }
public String cod {get;组; }
public String is_oda {get;组; } $ / $
public String state_code {get;组; }
}
任何人都可以给我适当的答案。
期待。
Hello,
How can i Parse json string into list. My json output list is as below:
{
"delivery_codes": [
{
"postal_code": {
"district": "Surat",
"pin": 395001,
"pre_paid": "Y",
"cash": "Y",
"pickup": "Y",
"cod": "Y",
"is_oda": "N",
"state_code": "GJ"
}
},
{
"postal_code": {
"district": "Surat",
"pin": 395009,
"pre_paid": "Y",
"cash": "Y",
"pickup": "Y",
"cod": "Y",
"is_oda": "N",
"state_code": "GJ"
}
}
]
}
My class Structure is :
public class postal_code_list
{
public String district { get; set; }
public String pin { get; set; }
public String pre_paid { get; set; }
public String cash { get; set; }
public String pickup { get; set; }
public String cod { get; set; }
public String is_oda { get; set; }
public String state_code { get; set; }
}
Can anyone give me appropriate answer.
looking forward.
推荐答案
所以...首先我用Google搜索:
将json解析为对象c#,它将我带到 here [ ^ ]。
然后我点击了第二个链接(因为我觉得它看起来更有前途)这让我这里 [ ^ ]。
最后,我阅读了提供的答案,并将其链接到此处:
使用C#反序列化JSON [ ^ ]
这是一个代码项目文章,我想我会查看是否它花了单个物品并将它们列为......哦它确实。
看看,尝试一些谷歌搜索它是惊人的你可以找到... 20秒。
So... First I googled this:
"parse json to object c#" which took me to here[^].
Then I clicked the second link (because I thought it looked more promising) which took me here[^].
Finally, I read the answer provided and saw it linked to here:
Deserialize JSON with C#[^]
Which being a codeproject article I thought I would check out to see if it took single objects and made them lists... oh it does.
Have a look, and try some googling it is amazing what you can find in... 20 seconds.
这篇关于将复杂JSON解析为c#List的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!