我以字符串形式从Google Directions API获得了jSON响应。我如何获取"机动"这个对象?我想将它放在另一个JSON数组中,稍后我将变成一个字符串。
这是我到目前为止所做的事情:
public JSONArray parseDirectionsForNavigation(String jsonData)
{
JSONArray jsonArray_live = null;
JSONObject jsonObject_live;
try {
jsonObject_live = new JSONObject(jsonData);
jsonArray_live = jsonObject_live.getJSONArray("routes").getJSONObject(0).getJSONArray("legs").getJSONObject(0).getJSONArray("steps");
} catch (JSONException e) {
e.printStackTrace();
}
return jsonArray_live;
}
答案 0 :(得分:1)
JSONArray arr_routes = jsono.getJSONArray("routes");
JSONArray arr_legs = jsono.getJSONArray("legs");
JSONArray arr_steps = jsono.getJSONArray("steps");
for (int i = 0; i < arr_steps .length(); i++) {
JSONObject object = jarray.getJSONObject(i);
//create a string array of some sort.
String[] maneuvers = object.getString("maneuvers")
}
您可以尝试很多其他解析方法,但在进入内部时,json可以这样做
也来自我自己的应用。
答案 1 :(得分:0)
<dependencies>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-tests</artifactId>
<version>7.2.1</version>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>dom4j</artifactId>
<groupId>dom4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${jira.version}</version>
<scope>provided</scope>
</dependency>
<!-- spock-core -->
<dependency>
<groupId>org.spockframework</groupId>
<artifactId>spock-core</artifactId>
<version>1.0-groovy-2.4</version>
<scope>test</scope>
</dependency>
<!-- Overrides the Groovy version specified by spock-core-->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.4</version>
<scope>test</scope>
</dependency>
<!-- Creates the test report -->
<dependency>
<groupId>com.athaydes</groupId>
<artifactId>spock-reports</artifactId>
<version>1.2.7</version>
<scope>test</scope>
</dependency>
</dependencies>