我正在尝试解析从文件流中获取的json文件。以下是我的json数据
{
"appname":"sine",
"taborder": [
"some",
"thing",
"is",
"went",
"wrong" ]
}
我将数据存储在String中并尝试反序列化数据。我试图以下列方式在警告框中显示密钥
string jsonString = contents;//"{'Name':'Bill', 'Ag:53}";
you deserializedUser = ReadToObject(jsonString);
var str = deserializedUser.mainDict.Keys.ToArray();
MessageBox.Show(str.ToString());
但我得到的关键值为“null”,如何正确获取关键值,请帮助我......
答案 0 :(得分:1)
我希望这有助于
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
JavaScriptRequest obj= DeserializeJavaScriptRequest(typeof(JavaScriptRequest), Resource1.test) as JavaScriptRequest;
MessageBox.Show(obj.appname +" | " + obj.taborder[0]);
}
public object DeserializeJavaScriptRequest(Type typedeserialize, string eValue)
{
Type t = typedeserialize;
// Get constructor info.
ConstructorInfo[] ci = t.GetConstructors();
object reflectOb = ci[0].Invoke(null);
MemoryStream confirm_ms = new MemoryStream(Encoding.UTF8.GetBytes(eValue));
DataContractJsonSerializer confirm_ser = new DataContractJsonSerializer(typedeserialize);
reflectOb = confirm_ser.ReadObject(confirm_ms);
confirm_ms.Close();
return reflectOb;
}
我上了课
public class JavaScriptRequest
{
public string appname { get; set; }
public string[] taborder { get; set; }
}