我想在Android中使用Google Places API添加我自己的位置并进行一些描述。现在我想在下面的字符串格式中添加邻域,URL,网站,international_phone_number等,但我无法得到它PLZ帮助我:
String placeJSON =
"{"+
"\"location\": {" +
"\"lat\": " + lat + "," +
"\"lng\": " + lng +
"}," +
"\"accuracy\":50.0," +
"\"name\": \"" + name + "\"," +
"\"types\": [\"" + type + "\"]," +
"\"vicinity\":\""+ DescriptionDialog.vic +"\","+
"\"formatted_address\":\""+ DescriptionDialog.formtd_address +"\","+
"\"formatted_phone_number\":\""+ DescriptionDialog.formtd_phone_number +"\","+
"\"url\":\""+ DescriptionDialog.myUrl +"\","+
"\"website\":\""+ DescriptionDialog.myWebsite +"\","+
"\"language\": \"en\" " +"}";
答案 0 :(得分:1)
为什么使用字符串来处理JSON。虽然您可以使用JSONObject,但这可以解决您的问题。
JSONObject placeJson = new JSONObject();
JSONObject location = new JSONObecjt();
location.put("lat", lat);
location.put("lon", lon);
placeJson.put("location", location);
placeJson.put("accuracy", 50.0);
placeJson.put("types", types);
placeJson.put("vicinity", DescriptionDialog.vic);
placeJson.put("formatted_address", DescriptionDialog.formtd_address);
placeJson.put("formatted_phone_number", DescriptionDialog.formtd_phone_number);
placeJson.put("url", DescriptionDialog.myUrl);
placeJson.put("website" DescriptionDialog.myWebsite);
placeJson.put("language", "en");