Parse array value from response and show it in UI

SreeeeSreeee INMember ✭✭✭✭✭
edited December 2018 in Xamarin.Forms

I have a response like below:

{
    "status": false,
    "errorDetails": [
        "An Error Occured During Registration"
    ],
    "userId": 0,
    "schoolId": 0,
    "planAmount": 0,
    "discountId": 0,
    "userProfileId": 0
}

I need to show the errorDetails content to UI if the status value is false. errorDetails is an array, so what was the type that I can use in the front end and how I can parse that value?

I tried like below:

public class SignUpResponse
{
    public bool status { get; set; }
    public string userProfileId { get; set; }
    public List<string> errorDetails { get; set; }
}

string error = "";
if (signUpdetails.errorDetails.Count > 0)
{
    error = signUpdetails.errorDetails[0];
}
if (!status)
{
    await DisplayAlert("Alert", error.ToString(), "OK");
} 

But this is not working, nothing is showing in the alert?

Best Answer

  • SreeeeSreeee IN ✭✭✭✭✭
    Accepted Answer

    My mistake, in my test scenario errordetails was empty. My code is working fine. Sorry guys for the foolish question.
    Hope this thread will help someone for parsing array value from the response and show it in UI.

Answers

  • SreeeeSreeee INMember ✭✭✭✭✭
    Accepted Answer

    My mistake, in my test scenario errordetails was empty. My code is working fine. Sorry guys for the foolish question.
    Hope this thread will help someone for parsing array value from the response and show it in UI.

Sign In or Register to comment.