sanyaade-teachings / json-simple

Automatically exported from code.google.com/p/json-simple
Apache License 2.0
0 stars 0 forks source link

JSONValue.writeJSONString should treat Array objects as JSONArray #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. For use with ServletRequest.getParameterMap()

//request map to json object to retrieve results via ajax
Writer out = //implementation specific
Map<String, String[]> requestMap = request.getParameterMap();
JSONObject.writeJSONString(requestMap, out);

2. Or with JSONObject utilizing Array instead of List

//simpler example
JSONObject ob = new JSONObject(); 
ob.put("a","value");
ob.put("b",new String[]{"arr1","arr2"});
ob.writeJSONString(out);

What is the expected output? What do you see instead?
(2)
Seen: {"b":[Ljava.lang.String;@654485dc,"a":"value"}
Expected: {"b":["arr1","arr2"],"a":"value"}

What version of the product are you using? On what operating system?

1.1, though the issue is unchanged in the latest code

Please provide any additional information below.

Suggest adding option to JSONValue:153 - in writeJSONString
/* start */
if(value.getClass().isArray()) {
    JSONArray arr = new JSONArray();
    for(Object valueItem: (Object[])value) { 
        arr.add(valueItem);
    }
    arr.writeJSONString(out);
    return;
}
/* end */

Thanks!

Mike

Original issue reported on code.google.com by michael....@gmail.com on 28 Mar 2012 at 1:22

GoogleCodeExporter commented 9 years ago

Original comment by fangyid...@gmail.com on 28 Mar 2012 at 2:48