JAVA 将{"status":1,"msg":"success","info":{"lines":[{"lineName":"星村专线","from":"汽车站","to":"星村","direction":"1","company":"武夷山市公共交通有限公司"}转数组
时间: 2023-12-11 12:33:47 浏览: 65
beijing-realtime-bus:Beijing 实时公交
可以使用Java中的JSON库将该JSON字符串转换为Java对象,然后获取其中的lines数组。以下是一个示例代码:
```java
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class Main {
public static void main(String[] args) {
String jsonStr = "{\"status\":1,\"msg\":\"success\",\"info\":{\"lines\":[{\"lineName\":\"星村专线\",\"from\":\"汽车站\",\"to\":\"星村\",\"direction\":\"1\",\"company\":\"武夷山市公共交通有限公司\"}]}}";
JSONObject jsonObj = JSON.parseObject(jsonStr);
JSONArray linesArr = jsonObj.getJSONObject("info").getJSONArray("lines");
System.out.println(linesArr.toJSONString());
}
}
```
输出结果为:
```
[{"company":"武夷山市公共交通有限公司","direction":"1","from":"汽车站","lineName":"星村专线","to":"星村"}]
```
阅读全文