0

我正在尝试解析从文件流中获取的 json 文件。以下是我的 json 数据

{
   "appname":"sine",
    "taborder":  [
            "some",
            "thing",
            "is",
            "went",
            "wrong"  ]
}

我将数据存储在字符串中并尝试反序列化数据。我正在尝试通过以下方式在警报框中显示键

 string jsonString = contents;//"{'Name':'Bill', 'Ag:53}";
 you deserializedUser = ReadToObject(jsonString);

 var str = deserializedUser.mainDict.Keys.ToArray();
 MessageBox.Show(str.ToString());

但是我将键值设为“null”,如何正确获取键值,请帮助我.....

4

1 回答 1

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; }
    }
于 2012-07-10T06:11:54.877 回答