gpt4 book ai didi

android如何从数组中包含数组的json中获取数据

转载 作者:搜寻专家 更新时间:2023-11-01 08:14:23 24 4
gpt4 key购买 nike

我有一个应用程序,我想从本地服务器获取数据。喜欢

{
"restarutant":{
"name":"Hotel Raja",
"photo":"http:\/\/i.imgur.com\/Mzt4u.jpg",
"address":"93, 2ndc ross, GDP etx.",
"area":"Vylaikaval",
"city":"Bangalore",
"location":["13.005621","77.577531"],
"phone":["9986377561","08023467969"],
"rating":"4",
"cuisines":["Chinese","Korean"],
"attributes":["smoking","parking","delivery"]
}
}

表示数组中的数组请任何人告诉我如何从中检索每个数据。谢谢

最佳答案

试试这段代码:

        String str_json = "your json string from query";

try {
JSONObject topobj = new JSONObject(str_json);
JSONObject innerobj = topobj.getJSONObject("restarutant");

String name = innerobj.getString("name");
String photo = innerobj.getString("photo");
JSONArray cuisines = innerobj.getJSONArray("cuisines");
//etc etc...

} catch (JSONException e) {
e.printStackTrace();
}

关于android如何从数组中包含数组的json中获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6304460/

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