Results 1 to 5 of 5
- 08-17-2010, 01:09 PM #1
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
JSONArray from JSON that doesn't contain any names?
Hi,
I'm new to Java. How would I turn this JSON string in to a JSONArray?
[{"Center":"10.337795657976551,-85.85095225274017","Name":"Playa Grande","URL":"http:\/\/jal.local\/playagrande\/"},{"Center":"0,0","Name":"Sandbox","URL":"htt p:\/\/jal.local\/sandbox\/"}]
The JSON objects in the array don't have any names so I can't use getJSONArray("name")
Thanks,
Joe
- 08-17-2010, 09:24 PM #2
Not sure if you tried this, but getJSONArray can take an int parameter, which is the index between 0 and length()-1. JSONArray
- 08-17-2010, 09:57 PM #3
Your example looks like a JSONStore
This is what I doJava Code:[{"Center":"10.337795657976551,-85.85095225274017","Name":"Playa Grande","URL":"http:\/\/jal.local\/playagrande\/"},{"Center":"0,0","Name":"Sandbox","URL":"htt p:\/\/jal.local\/sandbox\/"}]
I do not know if this would work.. but you may be able to tryJava Code:JSONObject store_example = new JSONObject(); JSONArray json_example = new JSONArray(); JSONObject obj_example = new JSONObject(); obj_example.put("Name", "Playa Grande"); obj_example.put("URL", "http:\/\/jal.local\/playagrande\/"); json_example.put(obj_example); store_example.put("Center",json_example);
Java Code:JSONArray json_example = new JSONArray(); json_example.put("[{"Center":"10.337795657976551,-85.85095225274017","Name":"Playa Grande","URL":"http:\/\/jal.local\/playagrande\/"},{"Center":"0,0","Name":"Sandbox","URL":"htt p:\/\/jal.local\/sandbox\/"}]");:rolleyes: ~ Sno ~ :rolleyes:
'-~ B.S. Computer Science ~-'
- 08-18-2010, 11:16 AM #4
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
Thanks for all of the replies. If I try:
Then I get an array with 12 elements in it. The first element contains the JSON text unchanged, the rest are all null.Java Code:JSONArray json_example = new JSONArray(); json_example.put("[{"Center":"10.337795657976551,-85.85095225274017","Name":"Playa Grande","URL":"http:\/\/jal.local\/playagrande\/"},{"Center":"0,0","Name":"Sandbox","URL":"htt p:\/\/jal.local\/sandbox\/"}]");
I'm running this on Android and getJSONArray doesn't seem to accept integer parameters.
Any ideas?
Thanks,
Joe
- 08-18-2010, 11:21 AM #5
Member
- Join Date
- Aug 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
hashmap to json
By prakashkadakol in forum New To JavaReplies: 5Last Post: 07-30-2011, 01:32 AM -
Json
By mac in forum New To JavaReplies: 10Last Post: 06-08-2010, 11:15 PM -
JSON Lib: json-lib-1.0-jdk13.jar
By Raghuraman K in forum Advanced JavaReplies: 3Last Post: 05-13-2010, 10:00 AM -
Put JSONObject to JSONArray?
By DigitalMan in forum Advanced JavaReplies: 3Last Post: 04-03-2010, 09:04 AM -
JSON Parsing
By prakashkadakol in forum New To JavaReplies: 1Last Post: 01-04-2010, 07:13 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks