Questions tagged [org.json]

A JSON processing library for Java.

A JSON processing library for Java, available from https://github.com/stleary/JSON-java.

History

Until January 2016, it was documented at http://www.json.org/java/ and hosted at https://github.com/douglascrockford/JSON-java.

Related

See also .

274 questions
82
votes
5 answers

The difference between getString() and optString() in Json

What is the difference between getString() and optString() in JSON?
oferiko
  • 1,927
  • 2
  • 16
  • 17
52
votes
7 answers

How do I clone an org.json.JSONObject in Java?

Is there a way to clone an instance of org.json.JSONObject without stringifying it and reparsing the result? A shallow copy would be acceptable.
Daniel Schaffer
  • 56,753
  • 31
  • 116
  • 165
42
votes
2 answers

How to use the org.json Java library with Java 7

I need some simple JSON parsing in my application and the Douglas Crockford library seems exactly what I need. However, I seem to be running into a problem. I'm getting the following error: Exception in thread "main"…
Luke
  • 20,878
  • 35
  • 119
  • 178
25
votes
3 answers

JSON.getString doesn't return null

I have a response coming back from a server and I am expecting a String value, so I wrote this for parsing it public String getMessageFromServer(JSONObject response) { String msg = response.getString("message"); return msg; } then, when I…
thepoosh
  • 12,497
  • 15
  • 73
  • 132
22
votes
3 answers

Parse JSON with org.json

I'm trying to parse an output from a server that looks like this: { "GetFolderFilesByZoneResult": [ { "ID": 98748, "CreatedBy": "", "UpdatedBy": "none", "CreatedDate": "\/Date(1308273033620+0100)\/", …
Paul Ulrich
  • 399
  • 1
  • 5
  • 13
20
votes
5 answers

How to convert Java String to JSON Object

This question has been asked earlier, but I am unable to figure out the error in my code from the responses to those questions. I am trying to convert a java string into json object. Here is the code: import org.json.JSONObject; //Other lines of…
Nishit
  • 1,276
  • 2
  • 11
  • 25
18
votes
1 answer

What version of org.json is built into Android?

I'm using an open source library that depends on org.json:json:20090211. Evidently there are some API differences between version 20090211 and whatever version is provided by Android. When I enable ProGuard minimization, I see this…
Kevin Krumwiede
  • 9,868
  • 4
  • 34
  • 82
15
votes
2 answers

Java object to JSON with org.json lib

I have class like this: public class Class1 { private String result; private String ip; private ArrayList alarm; } Where Alarm its a class like this: public class Class2 { private String bla; private String bla1; } Is…
Divers
  • 9,531
  • 7
  • 45
  • 88
9
votes
1 answer

Can't find org.json.JSONObject

I'm working on a Java project that uses the org.json.JSONObject package. However, whenever I use it in eclipse, it says that no such package was found. However, when I develop on android i.e. create a new Android project in eclipse, I can use it…
Rohan Prabhu
  • 7,180
  • 5
  • 37
  • 71
9
votes
2 answers

Creating JSON in java using org.json

I am trying to create a json string in java using org.json library and following is the code snippet. JSONArray jSONArray = new JSONArray(); JSONObject jSONObject = new JSONObject(); jSONObject.accumulate("test",…
raju
  • 4,788
  • 15
  • 64
  • 119
8
votes
3 answers

Why double is converted to int in JSON string

I just coded to put an array of double values in the JsonObject. But, all my double values are converted to int values, when i print it. can someone help me understand what is happening behind? Please let me know the best way to put primitive arrays…
Keerthivasan
  • 12,760
  • 2
  • 32
  • 53
6
votes
1 answer

Making JSON not Escape Forward Slashes

This is an extenuation of this question: JSON: why are forward slashes escaped? So I understand why JSON escapes the forwards slashes when I create a JSONArray that has Strings that contain URLs (links) in each of its indices. I would like to now…
Vinay
  • 6,204
  • 6
  • 38
  • 55
6
votes
3 answers

Can I get value from JSONObject without mention its name?

My JSONObject: {MyJSON:[{"id":"1","name":"panji","price":"100"}]} I do this to get value of id: menuitemArray.getJSONObject(i).getString("id"); Can I get the value of id, name or price, without mentioning its name, may be like index or another…
panji
  • 59
  • 1
  • 1
  • 5
5
votes
2 answers

How to prevent JSONObject from json.jar converts decimal numbers string into double

Using JSONObject to read a json response from a server. The server returns some decimal number. Normal numbers are not a problem to but the problem occurs when there is decimal number of form 0.00068. Numbers like 0.00068 are automatically stored…
Ameya
  • 1,914
  • 4
  • 29
  • 55
5
votes
1 answer

convert composite java object to CSV

I have an object, say Response.java that looks like the following: class Response { private User user; // has firstName, lastName, age etc. private Address address; // has city, state, country etc. private OrderInfo orderInfo; // has…
aazeem
  • 844
  • 1
  • 12
  • 23
1
2 3
18 19