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 に答える