问题描述
什么是最简单的C#函数来分析JSON字符串转换成一个对象,并显示它(C#WPF XAML)?
- (ARRA和ARRB例如用2个数组对象) DataContractJsonSerializer串行=
新DataContractJsonSerializer(typeof运算(YourObjectType));
YourObjectType yourObject =(YourObjectType)serializer.ReadObject(jsonStream);
您也可以使用 JavaScriptSerializer
,而 DataContractJsonSerializer
假想能更好地处理复杂的类型。
奇怪的是JavaScriptSerializer是pcated曾德$ P $(3.5),也因为ASP.NET MVC的然后复活(3.5 SP1)。这将肯定是足以动摇我的信心,并导致我使用 DataContractJsonSerializer
,因为它是经过高温烘烤的WCF。
What is the simplest C# function to parse a JSON string into a object and display it (C# XAML WPF)? (for example object with 2 arrays - arrA and arrB)
DataContractJsonSerializer serializer =
new DataContractJsonSerializer(typeof(YourObjectType));
YourObjectType yourObject = (YourObjectType)serializer.ReadObject(jsonStream);
You could also use the JavaScriptSerializer
, but DataContractJsonSerializer
is supposedly better able to handle complex types.
Oddly enough JavaScriptSerializer was once deprecated (in 3.5) and then resurrected because of ASP.NET MVC (in 3.5 SP1). That would definitely be enough to shake my confidence and lead me to use DataContractJsonSerializer
since it is hard baked for WCF.
这篇关于什么是最简单的C#函数来分析JSON字符串转换成一个对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!