3

Kindly need your help as this really taking me long time to try. From JSP, I passed the stingnify JSON object as a String to the Java action, it like

String jsonDealer = [{"dealerID":"VARSSWK103","dealerName":"NPD STATION SDN BHD"},
{"dealerID":"VARSSTH008","dealerName":"Winjaya Teleshop"}]

How I can convert this to JSON object/ or ArrayList of Dealer, so that I can retrieve the dealer ID and dealer name?

Thanks for all help!!!

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268
Callie
  • 41
  • 1
  • 2
  • 4

2 Answers2

-1

Well you could write your own JSON parser, but there's no need to re-invent the wheel - there are a number of robust, mature JSON parsers freely available. I use JSONObject and JSONArray from Tapestry. If you download Tapestry 5 and unpack it, then just include the library tapestry-core-5.0.18.jar in your build path and you'll be set to go. Both JSONObject and JSONArray take a String as constructor argument, and the api is fully documented in those links.

Richard H
  • 38,037
  • 37
  • 111
  • 138
-1

using http://json-lib.sourceforge.net/ can be realy easy.

See http://json-lib.sourceforge.net/snippets.html

String str = "{'dealerName':'NPD STATION SDN BHD', 'dealerID': 1, 'dealerReputation': 2.0, 'dealerActive': true}";  
JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( str );

and

String str = "['NPD STATION SDN BHD', 1, 2.0, true]";  
JSONArray jsonArray = (JSONArray) JSONSerializer.toJSON( str );
bbcooper
  • 1,082
  • 2
  • 10
  • 17