java, how to parse json ajax data as jsonArray?(using @requestparam map, not VO)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
java, how to parse json ajax data as jsonArray?
(using @requestparam map, not VO)
my js ajax code
$.ajax({
type : "POST"
,url : "/test"
,dataType : "json"
,data: {
"a": 123
, "b": "asdf"
, "c": "Y"
, "d": "Y"
, "test": new Array({"num":1, "use":"Y"},{"num":2, "use":"N"},{"num":3, "use":"Y"})
}
}).done(function(data){
}).fail(function(){
});
i did ajax data with stringify(). but did not parsing.
my java code
@ResponseBody
@RequestMapping(value="/test", method={RequestMethod.GET, RequestMethod.POST})
public String test(@RequestParam Map<String, Object> param, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
System.out.println(param);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject)jsonParser.parse(param.toString());
System.out.println(jsonObject);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
System.out.println(jsonObject.get("b"));
System.out.println(jsonObject.get("test"));
System.out.println(jsonArray.size());
return "";//helloworld.getName()+" Hello World! "+helloworld.getKind();
}
and i did,
JSONObject jsonObject = new JSONObject(param);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
but did not parsing.
System.out.print(jsonObject)
{a=123, b=asdf, c=Y, d=Y, test[0][num]=1, test[0][use]=Y, test[1][num]=2, test[1][use]=N, test[2][num]=3, test[2][use]=Y}
how can i parse, ajax json "test" array data.
why did not parsing??
java arrays json ajax parsing
add a comment |
java, how to parse json ajax data as jsonArray?
(using @requestparam map, not VO)
my js ajax code
$.ajax({
type : "POST"
,url : "/test"
,dataType : "json"
,data: {
"a": 123
, "b": "asdf"
, "c": "Y"
, "d": "Y"
, "test": new Array({"num":1, "use":"Y"},{"num":2, "use":"N"},{"num":3, "use":"Y"})
}
}).done(function(data){
}).fail(function(){
});
i did ajax data with stringify(). but did not parsing.
my java code
@ResponseBody
@RequestMapping(value="/test", method={RequestMethod.GET, RequestMethod.POST})
public String test(@RequestParam Map<String, Object> param, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
System.out.println(param);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject)jsonParser.parse(param.toString());
System.out.println(jsonObject);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
System.out.println(jsonObject.get("b"));
System.out.println(jsonObject.get("test"));
System.out.println(jsonArray.size());
return "";//helloworld.getName()+" Hello World! "+helloworld.getKind();
}
and i did,
JSONObject jsonObject = new JSONObject(param);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
but did not parsing.
System.out.print(jsonObject)
{a=123, b=asdf, c=Y, d=Y, test[0][num]=1, test[0][use]=Y, test[1][num]=2, test[1][use]=N, test[2][num]=3, test[2][use]=Y}
how can i parse, ajax json "test" array data.
why did not parsing??
java arrays json ajax parsing
use JSONArray jsonArray = jsonObject.getJSONArray("test"); it will help you.
– son pham
Nov 27 '18 at 2:11
um..i used org.json.JSONArray but error.(nested exception is org.json.JSONException: JSONObject["test"] not found)
– gdk
Nov 27 '18 at 3:57
add a comment |
java, how to parse json ajax data as jsonArray?
(using @requestparam map, not VO)
my js ajax code
$.ajax({
type : "POST"
,url : "/test"
,dataType : "json"
,data: {
"a": 123
, "b": "asdf"
, "c": "Y"
, "d": "Y"
, "test": new Array({"num":1, "use":"Y"},{"num":2, "use":"N"},{"num":3, "use":"Y"})
}
}).done(function(data){
}).fail(function(){
});
i did ajax data with stringify(). but did not parsing.
my java code
@ResponseBody
@RequestMapping(value="/test", method={RequestMethod.GET, RequestMethod.POST})
public String test(@RequestParam Map<String, Object> param, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
System.out.println(param);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject)jsonParser.parse(param.toString());
System.out.println(jsonObject);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
System.out.println(jsonObject.get("b"));
System.out.println(jsonObject.get("test"));
System.out.println(jsonArray.size());
return "";//helloworld.getName()+" Hello World! "+helloworld.getKind();
}
and i did,
JSONObject jsonObject = new JSONObject(param);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
but did not parsing.
System.out.print(jsonObject)
{a=123, b=asdf, c=Y, d=Y, test[0][num]=1, test[0][use]=Y, test[1][num]=2, test[1][use]=N, test[2][num]=3, test[2][use]=Y}
how can i parse, ajax json "test" array data.
why did not parsing??
java arrays json ajax parsing
java, how to parse json ajax data as jsonArray?
(using @requestparam map, not VO)
my js ajax code
$.ajax({
type : "POST"
,url : "/test"
,dataType : "json"
,data: {
"a": 123
, "b": "asdf"
, "c": "Y"
, "d": "Y"
, "test": new Array({"num":1, "use":"Y"},{"num":2, "use":"N"},{"num":3, "use":"Y"})
}
}).done(function(data){
}).fail(function(){
});
i did ajax data with stringify(). but did not parsing.
my java code
@ResponseBody
@RequestMapping(value="/test", method={RequestMethod.GET, RequestMethod.POST})
public String test(@RequestParam Map<String, Object> param, HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception {
System.out.println(param);
JSONParser jsonParser = new JSONParser();
JSONObject jsonObject = (JSONObject)jsonParser.parse(param.toString());
System.out.println(jsonObject);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
System.out.println(jsonObject.get("b"));
System.out.println(jsonObject.get("test"));
System.out.println(jsonArray.size());
return "";//helloworld.getName()+" Hello World! "+helloworld.getKind();
}
and i did,
JSONObject jsonObject = new JSONObject(param);
JSONArray jsonArray = (JSONArray)jsonObject.get("test");
but did not parsing.
System.out.print(jsonObject)
{a=123, b=asdf, c=Y, d=Y, test[0][num]=1, test[0][use]=Y, test[1][num]=2, test[1][use]=N, test[2][num]=3, test[2][use]=Y}
how can i parse, ajax json "test" array data.
why did not parsing??
java arrays json ajax parsing
java arrays json ajax parsing
edited Nov 27 '18 at 1:21
gdk
asked Nov 27 '18 at 1:15
gdkgdk
65
65
use JSONArray jsonArray = jsonObject.getJSONArray("test"); it will help you.
– son pham
Nov 27 '18 at 2:11
um..i used org.json.JSONArray but error.(nested exception is org.json.JSONException: JSONObject["test"] not found)
– gdk
Nov 27 '18 at 3:57
add a comment |
use JSONArray jsonArray = jsonObject.getJSONArray("test"); it will help you.
– son pham
Nov 27 '18 at 2:11
um..i used org.json.JSONArray but error.(nested exception is org.json.JSONException: JSONObject["test"] not found)
– gdk
Nov 27 '18 at 3:57
use JSONArray jsonArray = jsonObject.getJSONArray("test"); it will help you.
– son pham
Nov 27 '18 at 2:11
use JSONArray jsonArray = jsonObject.getJSONArray("test"); it will help you.
– son pham
Nov 27 '18 at 2:11
um..i used org.json.JSONArray but error.(nested exception is org.json.JSONException: JSONObject["test"] not found)
– gdk
Nov 27 '18 at 3:57
um..i used org.json.JSONArray but error.(nested exception is org.json.JSONException: JSONObject["test"] not found)
– gdk
Nov 27 '18 at 3:57
add a comment |
1 Answer
1
active
oldest
votes
i solved this question.
ajax option 'traditional:true' and json data, "test": JSON.stringify(new Array(...))
should send json in array object, use option 'traditional:true'.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491424%2fjava-how-to-parse-json-ajax-data-as-jsonarrayusing-requestparam-map-not-vo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
i solved this question.
ajax option 'traditional:true' and json data, "test": JSON.stringify(new Array(...))
should send json in array object, use option 'traditional:true'.
add a comment |
i solved this question.
ajax option 'traditional:true' and json data, "test": JSON.stringify(new Array(...))
should send json in array object, use option 'traditional:true'.
add a comment |
i solved this question.
ajax option 'traditional:true' and json data, "test": JSON.stringify(new Array(...))
should send json in array object, use option 'traditional:true'.
i solved this question.
ajax option 'traditional:true' and json data, "test": JSON.stringify(new Array(...))
should send json in array object, use option 'traditional:true'.
answered Nov 27 '18 at 5:25
gdkgdk
65
65
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491424%2fjava-how-to-parse-json-ajax-data-as-jsonarrayusing-requestparam-map-not-vo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
use JSONArray jsonArray = jsonObject.getJSONArray("test"); it will help you.
– son pham
Nov 27 '18 at 2:11
um..i used org.json.JSONArray but error.(nested exception is org.json.JSONException: JSONObject["test"] not found)
– gdk
Nov 27 '18 at 3:57