Question

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

This is my json format, And i'm try to deserialize it with the following class

   [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; }
}

and i call this class with the help of the follwing code

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

but while executing the above line i always get an error stating that,

     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.

help me to get out of this issue....

Was it helpful?

Solution

You have json "paid_through_account_name": "Petty Cash" where "Petty Cash" is string. But in your model property public Paid_Through_Account_Name has type int. Try change type to 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
}

Update

Probably you are trying to update the UI from the other (not main) thread. In Windows Phone app you can update UI only in main thread. In this case, use such construction 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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top