解析字节数组Json.Net到JSON [英] Parse byte array to json with Json.Net
本文介绍了解析字节数组Json.Net到JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图解析字节[]
阵列词典<弦乐,对象>
使用Json.Net但没有成功。
其实我在有关其可能性产生质疑。那么,这可能吗?与此库或与电气特性的库?
下面是我试过,但DeserializeObject节选仅字符串作为参数据我所知
公共静态字典<弦乐,对象>解析(字节[]的json){
&字典LT;弦乐,对象>值= JsonConvert.DeserializeObject<&字典LT;弦乐,对象>>(JSON);
返回值;
}
解决方案
是字节]
某种编码的文字?如果是这样,首先对其进行解码,例如如果编码是UTF8:
公共静态字典<弦乐,对象>解析(字节[]的json){
串jsonStr = Encoding.UTF8.GetString(JSON);
返回JsonConvert.DeserializeObject<&字典LT;弦乐,对象>>(jsonStr);
}
I'm trying to parse byte[]
array to Dictionary<String,Object>
using Json.Net but with no success
Actually I'm in doubt about its possibility. So is it possible? with this library or with anyother library?
here is what I have tried but DeserializeObject excepts only string as parameter afaik
public static Dictionary<String, Object> parse(byte[] json){
Dictionary<String, Object> values = JsonConvert.DeserializeObject<Dictionary<String, Object>>(json);
return values;
}
解决方案
Is the byte[]
some sort of encoded text? If so, decode it first, e.g. if the encoding is UTF8:
public static Dictionary<String, Object> parse(byte[] json){
string jsonStr = Encoding.UTF8.GetString(json);
return JsonConvert.DeserializeObject<Dictionary<String, Object>>(jsonStr);
}
这篇关于解析字节数组Json.Net到JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文