0

这是我的 Json 回复:

{
"value": [
    {
        "type": "school",
        "id": 12,
        "name": "NNPS",
        "city": "CA",
        "geo_position": {
            "latitude": 52.52437,
            "longitude": 13.41053
        }
    },
    {
        "type": "College",
        "id": 44,
        "name": "PEC",
        "city": "PE",
        "geo_position": {
            "latitude": 45.50298,
            "longitude": 10.04366
        }
    }
  ]
}

这是我使用“json.JSONArray”库的 java 代码:

while ((csvdata= br.readLine()) != null) {
  JSONObject output= new JSONObject(csvdata);
  JSONArray docs = output.getJSONArray("value");
  String csv = CDL.toString(docs);
  FileUtils.writeStringToFile(file, csv);
 }

当我检查csv文件时,它向我显示如下:

在此处输入图像描述 但它应该是这样的:

在此处输入图像描述 我正处于编码阶段的初期,目前正在改进它。请给我一些建议:)我应该如何改变它?

4

1 回答 1

1

您应该再次设置 lat 和 long 的水平。这对我有用

while ((csvdata= br.readLine()) != null) {
   JSONObject output= new JSONObject(csvdata);
   JSONArray docs = output.getJSONArray("value");

   for(int i=0; i<docs.length();i++){
       JSONObject geo_pos =  (JSONObject)(docs.getJSONObject(i).getJSONObject("geo_position"));
       docs.getJSONObject(i).put("latitude", geo_pos.get("latitude"));
       docs.getJSONObject(i).put("longitude", geo_pos.get("longitude"));
       docs.getJSONObject(i).remove("geo_position");
   }       

   String csv = CDL.toString(docs);
   FileUtils.writeStringToFile(file, csv);
 }
于 2013-12-07T22:26:58.553 回答