1

I declared an array as below

String[] finalcodes = new String[50] ;

and assigning some values to it finally when I print finalcodes it results as below.

["aaa","bbb","ccc"]

but my requirement is to get it as a json object

so please suggest me how to convert my string array to JSON Object.

User111
  • 95
  • 1
  • 2
  • 8
  • 3
    Use a framework like jackson to create json objects. – Jens Jan 29 '15 at 06:55
  • 1
    Your json object doesn't look valid. Where are the field names? – Hakan Serce Jan 29 '15 at 06:57
  • this link may be help you in this. [http://stackoverflow.com/questions/5245840/how-to-convert-string-to-jsonobject-in-java][1] [1]: http://stackoverflow.com/questions/5245840/how-to-convert-string-to-jsonobject-in-java – Vikas Chaudhary Jan 29 '15 at 06:58
  • eventhough it is not valid I need to build it like this, any suggestions – User111 Jan 29 '15 at 07:27
  • Suggestion 1: Don't call it JSON. Don't think like JSON. Create your own. – sarveshseri Jan 29 '15 at 07:28
  • JSON is key:value format, what are your keys, what are your values? – Mike Jan 29 '15 at 07:37
  • What several commenters are pointing out is that your example output is a JSON array, not a JSON object. I suspect you just have your terms confused. What do you mean by "JSON object"? If you don't mean what the actual JSON specification calls an object, please clarify. If the point is just to be able to parse the JSON in whatever system is receiving the data, then a JSON array is fine. – jpmc26 Jan 29 '15 at 07:51
  • Google Gson might help you out. – Sid Jan 29 '15 at 07:55

1 Answers1

1

You can use jackson library also check your json is valid; http://jackson.codehaus.org/ / http://jsonformatter.curiousconcept.com/

Habil
  • 540
  • 1
  • 8
  • 20