json - Android: put NameValuePair data in JSONObject -


i trying put namevaluepairdata jsonobject. namevaluepairdata has name string , value jsonarray. when tried put namevaluepairdata in jsonobject, jsonobject converts jsonarray value strings.

please check below code more details:

constructing namevaluepair:

list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(2);      namevaluepairs.add(new basicnamevaluepair("id", "1"));            jsonarray arr = new jsonarray();     if(arrbean != null && arrbean.size() > 0) {         (bean bean : arrbean) {             jsonobject idsjsonobject = new jsonobject();             try {                 idsjsonobject.put("min", bean.getmin());                 idsjsonobject.put("m1", bean.getmin());                 idsjsonobject.put("sec", bean.getsec());             } catch (jsonexception e) {                 e.printstacktrace();             }             arr.put(idsjsonobject);         }     }     namevaluepairs.add(new basicnamevaluepair("records", arr.tostring())); 

constructing jsonobject send httppost:

jsonobject jsonobjectdata = new jsonobject();      (namevaluepair namevaluepair : namevaluepairs) {         try {             jsonobjectdata.put(namevaluepair.getname(), namevaluepair.getvalue());         } catch (jsonexception e) {          }     } 

as shown above jsonobjectdata results following:

{"id":"1","records":"[{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"},{\"min\":\"610\",\"m1\":\"10\",\"sec\":\"\"}]"} 

you can see, automatically appends \"value\" inside array values. e.x. \"min\",\"m1\" etc...

any body has idea how avoid appending these \"value\".

please let me know. in advance.

both namevaluepair.getname() , namevaluepair.getvalue() return strings, added json strings. should pass jsonarray object second parameter in jsonobjectdata.put().

as basicnamevaluepair accept string values, try use hashmap<string, object> instead or recreate jsonarray string representation.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -