Trying to get data from a web service in Java
•
Java
[
[ { "title": "ginger","id": "38","product_id": "17","product_logo": "imagePath/Desert_0.jpg?itok=Uvm6nxpY","product_logo_1": "imagePath/Desert_0.jpg?itok=6YHK_afq","price": "$12.00" } ]
I'm working on a swing application in Java, and I need to get data from a web service
I'm following the this example to get data from a web service and store the web service data in a string
But I want to convert this string to JSON, and in some examples, one is this and this
So I just want to know what I did wrong here, or this is the right way to use it, because I don't know how to use web services in Java
Solution
You need to create its object before you need to use it
JSONObject jsnobject = new JSONObject(String); JSONArray jsonArray = jsnobject.getJSONArray("locations"); for (int i = 0; i < jsonArray.length(); i++) { JSONObject explrObject = jsonArray.getJSONObject(i); }
And make sure that in the code org json. Import this in jsonobject
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码