Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何操作JavaGeoJSON/JSON?_Java_Json_Api_Geojson - Fatal编程技术网

如何操作JavaGeoJSON/JSON?

如何操作JavaGeoJSON/JSON?,java,json,api,geojson,Java,Json,Api,Geojson,我正在以JSON/GEOJSON的形式从API(Aquaplot)检索数据。 这是数据存储方式的简单视图。 我想检索所有坐标并将它们存储在一个数组中 如何操作数据 { "type": "FeatureCollection", "features": [ { "type": "Feature", "properties": { "total_length": 558.49614719928, "seca_length": 0

我正在以JSON/GEOJSON的形式从API(Aquaplot)检索数据。 这是数据存储方式的简单视图。 我想检索所有坐标并将它们存储在一个数组中

如何操作数据

{   "type": "FeatureCollection",   "features": 
[
    {
      "type": "Feature",
      "properties": {
        "total_length": 558.49614719928,
        "seca_length": 0,
        "crossed": [
          "suez-canal"
        ]
      },
      "geometry": {
        "type": "LineString",
        "coordinates": [
          [32.67333984375, 33.174341551002],
          [32.3423, 31.2228],
          [32.310393, 31.094417],
          [32.319995, 30.811504],
          [32.342453, 30.703486],
          [32.305385, 30.568682],
          [32.396751, 30.357018],
          [32.449684, 30.285923],
          [32.500598, 30.260175],
          [32.52428, 30.244705],
          [32.560229, 30.198274],
          [32.585092, 29.973555],
          [32.567552, 29.923606],
          [32.714583, 29.448333],
          [33.237083, 28.553278],
          [34.018333, 27.504556],
          [35.92529296875, 24.806681353852]
        ]
      }
    }   ] }

你说的操纵是什么意思?是否要在某种数据结构中加载
JSON
数据(例如,
反序列化数据)?您可以显示为任何代码吗?请澄清您的问题。以上结果来自API。它的结果是JSON。我能够检索所有数据,但我只需要坐标部分来执行某种计算。更准确地说,我想在某种数据结构中加载JSON数据。谢谢。我现在可以检索API结果,但更准确地说,我想检索坐标部分。我该怎么做呢。我猜坐标是在一个嵌套数组中。整个响应是一个json对象。其中需要搜索几何体,而不是json数组坐标。我可以帮助你,如果你给我的网址和访问密钥
public static void main(String args[]) throws Exception
{
    //String url = "http://restcountries.eu/rest/v1/name/norway";
    String url = "     ";

    URL obj = new URL(url);
    HttpURLConnection con = (HttpURLConnection) obj.openConnection();

    // optional default is GET
    con.setRequestMethod("GET");

    //add request header
    con.setRequestProperty("Authorization", "   ");
    con.setRequestProperty("Content-Type", "application/json; charset=UTF-8");

    int responseCode = con.getResponseCode();
    System.out.println("\nSending 'GET' request to URL : " + url);
    System.out.println("Response Code : " + responseCode);
    System.out.println(con.getInputStream());


    BufferedReader in = new BufferedReader(
            new InputStreamReader(con.getInputStream()));
    String inputLine;
    StringBuffer response = new StringBuffer();

    while ((inputLine = in.readLine()) != null) {
        response.append(inputLine);

    }
    in.close();

    //print result
    System.out.println(response.toString());


    JSONObject jsonResponse=new JSONObject(response.toString());
    if(jsonResponse==null)
    {
    System.out.println("jsnresponse \n \n\n\n");
     throw new IllegalArgumentException("Books cannot be null");

    }



Fill the url and key .

response.tostring() is your response which further with the help pattern matcher you can parse and get the desired result.