gpt4 book ai didi

iphone - JSON解析数据iPhone

转载 作者:行者123 更新时间:2023-11-28 23:09:11 27 4
gpt4 key购买 nike

我如何解析此数据以使用它:我使用 NSString 获取以下数据并通过 NSLog 在控制台上显示它。

HTML = {"session":"2a1d9a1db71b443d7a9702816663d8d","role":"normal","account":"uid\u003ddemo@url.com,o\u003dDemo,o\u003dUnd"}

我想获取帐户的值,然后使用它们来选择其中一个我将使用选择器 View 的帐户。

和这个数据数组:

Group = ["DEMO"]

谢谢

最佳答案

您可以在 NSDictionary 中获取此 html 响应,然后使用以下代码访问它的元素

NSDictionary *html = [responseString JSONValue];
NSString * session = [html objectForKey:@"session"]//returns session id
NSString * role = [html objectForKey:@"role"]
NSString *accounts = [html objectForKey:@"account"]//This will get the accounts string with comma separated.
NSArray *accountList = [account componentsSeparatedByString:@","];//It will return the array of all acount values which you can use in picker view to select one

您可以通过检查数组大小来检查这一点

if(accountList.count>1)
{
//contains multiple accounts
}
else (if(accountList.count == 1)
{
//only one account
}
else
{
//No account
}

关于iphone - JSON解析数据iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8699661/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com