java - Get JSONArray and write to JSONArray -


i have following object:

{   "some_prop": "sweetvalue",   "some_list": ["0f9f822cd7e64000ac056ebc17b82f1d", "0f9f82223094fj7b82f1d"] } 

and i'm trying some_list , write some_list, afterwards saving file. using following code:

public string getdata(string key) { // confusion should getconfigvalue     string data = getconfig();     jsonobject jsondata;     object content = null;     try {         jsondata = new jsonobject(data);         if (key != null) {             content = jsondata.getstring(key);         } else {             content = jsondata.tostring();         }     } catch (jsonexception e) {         e.printstacktrace();     }     return content.tostring(); }  private void savefile(string data) {     file file = configfile;     try (fileoutputstream fop = new fileoutputstream(file)) {         if (!file.exists()) file.createnewfile();         byte[] contentinbytes = data.getbytes();         fop.write(contentinbytes);         fop.flush();         fop.close();     } catch (ioexception e) {         e.printstacktrace();     } }  public void appendtoarrayvalue(string uuid) {     jsonobject configdata = new jsonobject(getconfig());     jsonarray mutedplayers = configdata.getjsonarray("some_list");     jsonarray uuidarray = new jsonarray(uuid);      jsonarray newarray = concatarray(mutedplayers, uuidarray);      jsonobject newconfigdata = configdata.put("some_list", newarray);     savefile(newconfigdata.tostring()); } 

when trying run code, following error:

org.json.jsonexception: jsonarray text must start '[' @ 1 [character 2 line 1]

i'm not sure what's wrong, know code terrible that's it.

looks error @ line jsonarray uuidarray = new jsonarray(uuid);?

because prevoius line jsonarray mutedplayers = configdata.getjsonarray("some_list"); should work fine. if so, passing not array new jsonarray(uuid) since uuid whole json object.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -