jsonobject

Returning JsonObject using @ResponseBody in SpringMVC

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using the new Java API (JSR 353) for JSON in a SpringMVC project. The idea is to generate some piece of Json data and have it returned to the client. The controller I have look somewhat like this: @RequestMapping("/test") @ResponseBody public JsonObject test() { JsonObject result = Json.createObjectBuilder() .add("name", "Dade") .add("age", 23) .add("married", false) .build(); return result; } And when I access this, instead of getting the expected representation of the JSON, I get these instead: {"name":{"chars":"Dade","string":"Dade",

How to parse a dynamic JSON key in a Nested JSON result?

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a JSON result in the following format which JSON Lint shows this as a "Valid Response". My question is: how do I access the content of "question_mark" since "141", "8911", etc are all dynamic values? My sample code for accessing value of "product". //Consider I have the first JSONObject of the "search_result" array and //I access it's "product" value as below. String product = jsonObject.optString("product"); //where jsonObject is of type JSONObject. // product now contains "abc". JSON: { "status": "OK", "search_result": [ { "product"

AssertionError in Gson EnumTypeAdapter when using Proguard Obfuscation

匿名 (未验证) 提交于 2019-12-03 02:05:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My project implements a TypeAdapter in Gson during serialization/deserialization for preserving object's polymorphism state. Anyhow, the project works fine during development tests, but when it is released with proguard obfuscation and tested, it just crashes. 03-21 10:06:53.632: E/AndroidRuntime(12441): FATAL EXCEPTION: main 03-21 10:06:53.632: E/AndroidRuntime(12441): java.lang.AssertionError 03-21 10:06:53.632: E/AndroidRuntime(12441): at com.google.gson.internal.bind.TypeAdapters$EnumTypeAdapter. (SourceFile:724) 03-21 10:06:53.632: E

JSON and Generics in Java - Type safety warning

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have some data stored in Java elements and I need to return it in a given format - JSONObject. While my implementation works fine, I'm still getting a warning message from eclipse (Version: Juno Service Release 2): " Type safety: The method put(Object, Object) belongs to the raw type HashMap. References to generic type HashMap should be parameterized " This is my code: public interface Element {...} public abstract class AbstractElement implements Element {...} public final class Way extends AbstractElement {...} import java.util.ArrayList

How to return JSONObject from doInBackground() method to onPostExecute() method on AsyncTask?

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In Android app i want to return JSONObject from doInBackground() method to onPostExecute() method. Here is the code: private class AddAsyncTask extends AsyncTask { JSONObject jsonObjRecv; String result; @Override protected JSONObject doInBackground(JSONObject... params) { AssetObj assetObj = new AssetObj(); assetObj.setAssetName(txtname.getText().toString()); assetObj.setMobileNo(txtmobile.getText().toString()); assetObj.setOwnerId(myApp.getOwnerId()); assetObj.setStartTime(startTime.getText().toString()); assetObj.setEndTime(endTime.getText

Convert JsonObject to String

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: { "data": { "map": { "allowNestedValues": true, "create": "2012-12-11 15:16:13", "title": "test201212110004", "transitions": [] } }, "msg": "success", "code": "0" } Above is a JsonObject , the data is a JsonObject . How to convert it to a String like "msg":"success" as you know, i can't directly add a double quotes outside data 's value. 回答1: @hsz we have inbuild method to convert jsonObject to string. Why don't you use that. JSONObject json = new JSONObject(); json.toString(); 回答2: you can use JsonObject.getString("msg"); 回答3: Add a double

JSON order mixed up

匿名 (未验证) 提交于 2019-12-03 01:49:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've a problem trying to making my page printing out the JSONObject in the order i want. In my code, I entered this: JSONObject myObject = new JSONObject(); myObject.put("userid", "User 1"); myObject.put("amount", "24.23"); myObject.put("success", "NO"); However, when I see the display on my page, it gives: JSON formatted string: [{"success":"NO","userid":"User 1","bid":24.23} I need it in the order of userid, amount, then success. Already tried re-ordering in the code, but to no avail. I've also tried .append ....need some help here thanks!

JSON type mismatch or org.json.jsonecxeption

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The link is http://iipacademy.in/askpoll/ten_feed.php exception is in onPostExecute() method (4th line) : Log.i("result", result); try { if (result != null) { JSONArray jsonArray = new JSONArray(result); // erreor for (int i = 0; i LOGCAT: 12-18 03:20:45.447: W/System.err(2790): org.json.JSONException: Value response of type java.lang.String cannot be converted to JSONArray 12-18 03:20:45.447: W/System.err(2790): at org.json.JSON.typeMismatch(JSON.java:111) 12-18 03:20:45.447: W/System.err(2790): at org.json.JSONArray. (JSONArray.java:91) 12

JSON type mismatch or org.json.jsonecxeption

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The link is http://iipacademy.in/askpoll/ten_feed.php exception is in onPostExecute() method (4th line) : Log.i("result", result); try { if (result != null) { JSONArray jsonArray = new JSONArray(result); // erreor for (int i = 0; i LOGCAT: 12-18 03:20:45.447: W/System.err(2790): org.json.JSONException: Value response of type java.lang.String cannot be converted to JSONArray 12-18 03:20:45.447: W/System.err(2790): at org.json.JSON.typeMismatch(JSON.java:111) 12-18 03:20:45.447: W/System.err(2790): at org.json.JSONArray. (JSONArray.java:91) 12

Creating new JSONObject from String Returns Null - JAVA / Android

匿名 (未验证) 提交于 2019-12-03 01:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm attempting to create a new JSONObject from a String however for some reason the new JSONObject is always null - and I'm unsure why. Any suggestions are appreciated. Source: JSONObject messagesObj; String mArr = intent.getStringExtra("msgArr"); try { if (mArr != null) messagesObj = new JSONObject(mArr); if (messagesObj != null) populateMessages(messagesObj); DataManager.clientChatMarkMessagesSeen(chatId); } catch (JSONException e) { // DataManager.clientChatLoad(this); e.printStackTrace(); } Values: String mArr = [{"message":"User has