Xamarin.Forms: 从响应中解析数组值并将其显示在UI中。

问题描述 投票:0回答:1

我有一个如下的响应。

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

我需要在状态值为false的情况下向UI显示errorDetails的内容。errorDetails是一个数组,那么我在前端可以使用的类型是什么,我如何解析该值?

我试过像下面这样。

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");
} 

但这是不工作的,没有任何显示在警报中?

arrays json parsing xamarin xamarin.forms
1个回答
1
投票

看起来像一个JSON响应,它是否被正确地读入对象?IE:测试时对象中存在errorDetails?

请确认整体对象和errorDetails都是填充的,而不是空的或空的。

© www.soinside.com 2019 - 2024. All rights reserved.