迭代JSON&将其转换为C# [英] Iterate JSON & Convert it to C#
本文介绍了迭代JSON&将其转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我想迭代这个json并将其转换为C#对象,但问题是standard_room和executive_room是动态的,它可以是任何其他类型的房间也是如此无法在设计时创建任何类。
{
room_types:{
Standard_Room :{
price: 13136 。 200000 ,
费用: 0 ,
fees_at_checkout: 0 ,
tax: 0 ,
taxes_at_checkout: 0 ,
final_price: 13136 。 200000 ,
currency: INR,
num_rooms: 1
},
Executive_Room:{
price: 10771 。 684000 ,
费用: 0 ,
fees_at_checkout: 0 ,
税: 0 ,
taxes_at_checkout: 0 ,
final_price: 10771 。 684000 ,
currency: INR,
num_rooms: 1
}
}
}
解决方案
< blockquote>尝试 fastJSON.JSON.ToDynamic()
: fastJSON [ ^ ]
< blockquote>你可以做h好像,
如果你想转换这个JSON那么,
例如,
类房间
{有些房产}
房间[] obj = null;
JavaScriptSerializer ser = new JavaScriptSerializer();
obj = ser.Deserialize(JsonString,typeof(Rooms []))as Rooms [];
如果想要这个列表那么,
List< rooms> room = obj.toList< rooms>();
让我们知道它是怎么回事。
感谢。
Hello,
I want to iterate this json and convert it to C# object but problem is standard_room and executive_room are dynamic it can be anything other room type also so cannot create any classes at design time.
{
"room_types":{
"Standard_Room":{
"price":13136.200000,
"fees":0,
"fees_at_checkout":0,
"taxes":0,
"taxes_at_checkout":0,
"final_price":13136.200000,
"currency":"INR",
"num_rooms":1
},
"Executive_Room":{
"price":10771.684000,
"fees":0,
"fees_at_checkout":0,
"taxes":0,
"taxes_at_checkout":0,
"final_price":10771.684000,
"currency":"INR",
"num_rooms":1
}
}
}
解决方案
Try fastJSON.JSON.ToDynamic()
: fastJSON[^]
you can do here like,
if you want to convert this JSON then,
Example,
Class Rooms
{With some properties}
Rooms[] obj=null;
JavaScriptSerializer ser = new JavaScriptSerializer();
obj = ser.Deserialize(JsonString, typeof(Rooms[])) as Rooms[];
if want this to be list then,
List<rooms> room=obj.toList<rooms>();
let us know how it goes.
Thanks.
这篇关于迭代JSON&将其转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文