gpt4 book ai didi

java - JSON解析: One key,多个值

转载 作者:太空宇宙 更新时间:2023-11-04 11:41:03 25 4
gpt4 key购买 nike

我在如何解析以下数据方面遇到了一些麻烦:

[{
"Name": "EB DAVIE ST FS HOWE ST",
"Latitude": 49.27755,
"Longitude": -123.12698,
"Routes": "006, C23" }]

我想获取“Routes”的所有值。然后我想从每个字符串创建一个新的“路线”,并将每个“路线”存储在一个集合中。但我不知道如何迭代它..(对于这个例子,我们可以说每个路由只有一个名称)。

到目前为止我已经:

        JSONObject stop = allStops.getJSONObject(i);
JSONArray array = stop.getJSONArray("Routes");

for(int i = 0; i < array.length(); i++) {
Route r = new Route(array.get(i)) // i thought (array.get(i)) would give you the String of each value (e.g. "006")
Set<Route> routes = new HashSet<Route>();
routes.add(array.get(i)); // then I thought I should just add each route
}

但这不起作用。我不知道该怎么办。

最佳答案

String routes = stop.getString("Routes");
String[] split_routes = routes.split(", "); /*all routes will be stored in this array*/

关于java - JSON解析: One key,多个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42778671/

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