3

我想在 android 中使用 Google Places API 添加我自己的地方,并附上一些描述。现在我想以下面的字符串格式添加附近、URL、网站、international_phone_number 等,但我无法得到它请帮助我:

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\" " +"}";
4

1 回答 1

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");    
于 2012-10-31T13:28:13.610 回答