0
  {
   "code": 0,
   "message": "success",
   "expense": {
           "account_name": "Printing and Stationery",
           "paid_through_account_name": "Petty Cash"
              }
  }

这是我的 json 格式,我正在尝试使用以下类对其进行反序列化

   [DataContract]
public class Expenses
{

    [DataMember(Name = "code")]
    public int Code { get; set; }

    [DataMember(Name = "message")]
    public string Message { get; set; }

    [DataMember(Name = "expense")]
    public Expense Expense { get; set; }
}

[DataContract]
public class Expense
{
    [DataMember(Name = "account_name")]
    public string Account_Name { get; set; }

    [DataMember(Name = "paid_through_account_name")]
    public int Paid_Through_Account_Name { get; set; }
}

我在以下代码的帮助下调用这个类

     var myObjects = JsonConvert.DeserializeObject<Expenses>(json);

但是在执行上述行时,我总是收到一条错误消息,

     An exception of type 'System.UnauthorizedAccessException' occurred in     PhoneApp18.DLL but was not handled in user code

 If there is a handler for this exception, the program may be safely continued.

帮我摆脱这个问题....

4

1 回答 1

0

你有json "paid_through_account_name": "Petty Cash" 其中 "Petty Cash" 是string。但是在您的模型属性中, public Paid_Through_Account_Name有 type int。尝试将类型更改为string.

[DataContract]
public class Expense
{
    [DataMember(Name = "account_name")]
    public string Account_Name { get; set; }

    [DataMember(Name = "paid_through_account_name")]
    public string Paid_Through_Account_Name { get; set; } //string type
}

更新

可能您正在尝试从另一个(非主)线程更新 UI。在 Windows Phone 应用程序中,您UI 只能在主线程中更新。在这种情况下,使用这样的构造 Dispatcher。

 Dispatcher.BeginInvoke(() =>
                    {
                          TextBox.Text = myString;
                    });

http://msdn.microsoft.com/en-us/library/ms741870.aspx

http://weimenglee.blogspot.ru/2013/07/windows-phone-tip-updating-ui-from.html

于 2013-10-16T05:36:46.330 回答