0

I have an ArrayList<String> that I want to save into MySql database using restapi from my server. I create the ArrayList from value of checked item in ListView.

After populate the data I insert the ArrayList into a single column in MySql using Fast Android Networking (FAN) Library. Upon inserting I convert the ArrayList into string using toString() method.

The problem is the saved ArrayList is not in the format I expected it to be. It saved in format like this:

"[jon, doe, jane, doe]"

What I want is the ArrayList is save in this format:

["jon", "doe", "jane", "doe"]

Please help me how to do it.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
  • If i understand you problem correctly, you need need convert your ArrayList to JSON string. Look this question https://stackoverflow.com/questions/4841952/convert-arraylistmycustomclass-to-jsonarray. – Alisher Gafurov Jun 06 '17 at 07:50
  • nice, thank you for the answer. Now the inserted value looks like this "[\"123\",\"456\"]" how to remove the doublequote outside the bracket? – Riddict Dev Jun 06 '17 at 08:12
  • Now when you want get the data from DB and use in your app you need do the reverse operation - convert JSON string to ArrayList. For example https://stackoverflow.com/questions/17037340/converting-jsonarray-to-arraylist. – Alisher Gafurov Jun 06 '17 at 08:17
  • But unfortunately, what my user will do next will be occured in web server, not in android apps – Riddict Dev Jun 06 '17 at 09:58
  • What are you using in backend of the web server ? PHP, nodeJS, Python ? – Alisher Gafurov Jun 06 '17 at 10:10
  • PHP with Laravel as Framework. – Riddict Dev Jun 06 '17 at 11:38
  • Hey, how can I tag your comment as an answer. I figured it out now. thanks for your help. – Riddict Dev Jun 06 '17 at 12:31

0 Answers0