gpt4 book ai didi

android - 如何检查键值是字符串还是整数(ios,Android)

转载 作者:行者123 更新时间:2023-11-30 11:35:38 26 4
gpt4 key购买 nike

大家好,我是应用程序开发新手,我有一个 json 数据,并且有键(order_id),有时 order_id 值返回(“order_id”:“188”),但有时返回像这样的整数(“order_id”) : 188) .有没有办法找到 ios(swift) 和 android 中返回字符串或整数,谢谢

这是 json 响应的示例

"orders": [
{
"order_id": "188",
"invoice_id": "OR180413-188",
"order_status": "1"
}
]

还有这样的时候

"orders": [
{
"order_id": 188,
"invoice_id": "OR180413-188",
"order_status": "1"
}
]

最佳答案

安卓:

Object order_id = jsonarray.getJsonObject(0).getInt("order_id");
Object invoice_id = jsonarray.getJsonObject(0).getString("invoice_id");
Object order_status= jsonarray.getJsonObject(0).getInt("order_status");

if(order_id instanceOf String)
// do what you want
.....

也许这会对你有所帮助

关于android - 如何检查键值是字符串还是整数(ios,Android),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49817501/

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