编码对象JSON [英] Encode object to JSON
本文介绍了编码对象JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
希望我不必在这里重新发明轮子,但没有人知道是否有在C#类似于Adobe获得AS3到一个通用的对象转换为JSON字符串?
$ B提供的一个类$ b
例如,当我编码对象的数组。
新JSONEncoder(ARR).getString();
输出:
[
{类型:手机,数:02-8988-5566},
{类型:手机,数字: 02-8988-5566}
]
解决方案
在C#中:
VAR jsonSerializer =新System.Web.Script.Serialization.JavaScriptSerializer();
JSON字符串= jsonSerializer.Serialize(yourCustomObject);
Hoping I don't have to reinvent the wheel here but does anyone know if there is a class in C# similar to the one supplied by Adobe for AS3 to convert a generic object to a JSON string?
For example, when I encode an array of objects.
new JSONEncoder(arr).getString();
Output:
[
{"type":"mobile","number":"02-8988-5566"},
{"type":"mobile","number":"02-8988-5566"}
]
解决方案
in C#:
var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string json = jsonSerializer.Serialize(yourCustomObject);
这篇关于编码对象JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文