-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Issue 1660 & 1680 #1695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue 1660 & 1680 #1695
Conversation
Changed the access modifier for the constructor JSONArray(JSONTokener) to protected so that the other json classes can access it. Removed the extra JSONTokener inner class in JSONObject, this caused classes outside of JSONObject to use the wrong constructor JSONObject(Object bean) instead
It now accepts a JSONObject (or JSONArray) as parameter instead of a simple string. Error: The method setJSONObject(String, String) in the type JSONObject is not applicable for the arguments (String, JSONObject) The method setJSONArray(String, String) in the type JSONObject is not applicable for the arguments (String, JSONArray)
Fixed the JSON example. I left the data.json formatted as it was, however it is not as "sleek" as it could be. The json could start with the array straight away and that way cut away alot of the unnecessary code required to maintain the format through load and save.
|
A thought... should the JSON data have the same workflow as XML? JSON root = loadJSON("data.json"); |
|
loadJSON() or something similar is the plan yes, it just hasn't been implemented yet. I threw together that demo JSON data file quickly and agree it should be stripped to start directly with an array. |
|
I'm trying to wrap my head around this... but the only solution I can think of is wrapping the two JSON types in one class. If you don't do that the processing-user needs to typecast at some point, right? |
|
Here's my proposition then; using just one single JSON class to work with the text. This class encapsulates the JSONObject and JSONArray classes, making sure to instantiate the correct type based on the json formatted text - and warning if the text if not formatted correctly (it's neither a JSONObject or a JSONArray). When accessing the members of the inflated JSON type it will warn if you're using the wrong method, f.ex. trying to use getInt(int) on a JSON of type Object will throw an error saying that it's the wrong type. And perhaps even hinting at the correct method to use instead. My test program is as follows: JSON json = loadJSON("obj.json"); String myString = json.getString("myString"); int myInt = json.getInt("myInt"); float myFloat = json.getInt("myFloat"); double myDouble = json.getDouble("myDouble"); boolean myBoolean = json.getBoolean("myBoolean"); JSON myObject = json.getJSON("myObject"); int innerInt = myObject.getInt("innerInt"); JSON myArray = json.getJSON("myArray"); int arrayInt = myArray.getInt(0); Go ahead and close this, I'll open another pull where you can view the proposition. I added it in a new branch in my fork. |
|
This is all in progress... there are a handful of fixes in there now, and the next beta will get things sorted out properly. Stay tuned... |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Changed the access modifier for the constructor JSONArray(JSONTokener)
to protected so that the other json classes can access it.
Removed the extra JSONTokener inner class in JSONObject, this caused
classes outside of JSONObject to use the wrong constructor
JSONObject(Object bean) instead