Quando eu tendo dar um “JSONObject.fromObject” esta estourando uma exceção aqui ‘true’ = ‘true’ pq a aspas simples estão dentro de outra aspas simples, alguem sabe algum tipo de caracter de escape para essa API?
[code]public static void main(String[] args) {
String json = "{gA:[ {c:{f:'C#',o:'=',v1:' ('true' = 'true' ) ' }}]}";
//final Map<String, Object> map = new HashMap<String, Object>();
try {
JsonConfig cfg = new JsonConfig();
cfg.setRootClass(LinkedHashMap.class);
cfg.setArrayMode(JsonConfig.MODE_OBJECT_ARRAY);
cfg.setHandleJettisonSingleElementArray(false);
JSONObject jsonObjeto = JSONObject.fromObject(clearForJSON(json), cfg);// estoura a exceção
System.out.println(jsonObjeto.toString());
} catch (final JSONException e) {
e.printStackTrace();
}
}
public static String clearForJSON(String evaluate) {
if (evaluate == null) {
return null;
}
evaluate.replaceAll("\r\n", " ");
evaluate = evaluate.replaceAll("\n", " ");
evaluate = evaluate.replaceAll("\r", " ");
evaluate = evaluate.replaceAll("\f", " ");
//evaluate = evaluate.replaceAll("'", "\'");
return evaluate;
}[/code]
Exceção que estoura:
net.sf.json.JSONException: Expected a ',' or '}' at character net.sf.json.JSONException: Expected a ',' or '}' at character 31 of {gA:[ {c:{f:'C#',o:'=',v1:' ('true' = 'true' ) ' }}]}
at net.sf.json.util.JSONTokener.syntaxError(JSONTokener.java:499)
at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1099)
at net.sf.json.JSONObject.fromObject(JSONObject.java:159)
at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:348)
at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1008)
at net.sf.json.JSONObject.fromObject(JSONObject.java:159)
at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:348)
at net.sf.json.JSONArray._fromJSONTokener(JSONArray.java:1131)
at net.sf.json.JSONArray.fromObject(JSONArray.java:125)
at net.sf.json.util.JSONTokener.nextValue(JSONTokener.java:351)
at net.sf.json.JSONObject._fromJSONTokener(JSONObject.java:1008)
at net.sf.json.JSONObject._fromString(JSONObject.java:1201)
at net.sf.json.JSONObject.fromObject(JSONObject.java:165)
at br.com.michel.json.JsonTest.main(JsonTest.java:28)
Desde já agradeço a todos