Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@agoransson
Copy link

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

Andreas Göransson added 3 commits March 20, 2013 10:25
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.
@agoransson
Copy link
Author

A thought... should the JSON data have the same workflow as XML?

JSON root = loadJSON("data.json");
root.getJSONObject("...");
root.getInt("...");

@shiffman
Copy link
Member

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.

@agoransson
Copy link
Author

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?

@agoransson
Copy link
Author

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");
println(json);

String myString = json.getString("myString");
println( myString );

int myInt = json.getInt("myInt");
println( myInt );

float myFloat = json.getInt("myFloat");
println( myFloat );

double myDouble = json.getDouble("myDouble");
println( myDouble );

boolean myBoolean = json.getBoolean("myBoolean");
println( myBoolean );

JSON myObject = json.getJSON("myObject");

int innerInt = myObject.getInt("innerInt");
println( innerInt );

JSON myArray = json.getJSON("myArray");

int arrayInt = myArray.getInt(0);
println( arrayInt );

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.

@benfry
Copy link
Contributor

benfry commented Apr 11, 2013

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...

@benfry benfry closed this Apr 11, 2013
@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.