0

我想知道如何为 findNearbyWiki 创建类似于 geonames api 的 JSON,而不是使用我想定义自己的数据的 wiki 数据。但是我不知道怎么做。我键入 json 数组并将其命名为 a.json。我在服务器中上传我的 a.json ......但它无法查看.. 这里是我的 json 文件

{"geonames":
[
{"summary":"Universiti Teknologi Malaysia (University of Technology Malaysia, UTM) is the oldest public engineering and technological university in Malaysia. The university specialises in technical studies, with separate faculties for Education, Pure Sciences, Management, and Human Resources Development (...)",
"distance":"0.0185",
"rank":90,
"title":"Universiti Teknologi Malaysia",
"wikipediaUrl":"en.wikipedia.org/wiki/Universiti_Teknologi_Malaysia",
"elevation":26,
"countryCode":"MY",
"lng":103.641486,
"feature":"landmark",
"lang":"en",
"lat":1.559034
}
]
}
4

3 回答 3

0

使用 JsonObject 和 JsonArray 类将所有信息放入对象中,然后在主 JsonObject 上调用 toString 方法。那会为你做到这一点。

于 2012-10-27T15:58:37.797 回答
0

使用JSONObject

put 方法添加或替换对象中的值。例如,

myString = new JSONObject().put("JSON", "Hello, World!").toString();
produces the string {"JSON": "Hello, World"}.
于 2012-10-27T15:58:39.450 回答
0
    JSONObject mainObject = new JSONObject();
    JSONArray geonames = new JSONArray();
    JSONObject item = new JSONObject();
    item.put("summary", "Universiti Teknologi Malaysia (University of Technology Malaysia, UTM) is the oldest public engineering and technological university in Malaysia. The university specialises in technical studies, with separate faculties for Education, Pure Sciences, Management, and Human Resources Development (...)");
    item.put("distance", 0.0185f);
    item.put("rank", "90");
    item.put("title", "Universiti Teknologi Malaysia");
    item.put("wikipediaUrl", "en.wikipedia.org/wiki/Universiti_Teknologi_Malaysia");
    item.put("elevation", "26");
    item.put("countryCode", "MY");
    item.put("lng", 103.641486f);
    item.put("lang", "en");
    item.put("feature", "landmark");
    item.put("lat", 1.559034f);
    geonames.put(item);
    mainObject.put("geonames", geonames);
    String jsonString = mainObject.toString();  

这正是您所需要的

于 2012-10-27T16:50:36.670 回答