We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a JSON formatted string that I want to load into a JSON object. I cannot read this from a file or a URL, I need to parse the string. Any help greatly appreciated.
Answers
https://www.processing.org/reference/loadJSONObject_.html
Hi Chrisir, loadJSONObject() assumes you are loading the data from a file or a URL, as I said in my post I cannot use either and if you try to load a string you get the error "The function loadJSONObject(String) does not exist"
never mind
doesn't work
here...
they forgot it in the reference...
but it works similar to parseXML() I think....
;-)
I had tried that earlier and got the error "the constructor JSONObject(Object) is not visible" I am using Processing 2.0.2, I assume you are using a later version in which it is visible?
it's still not trivial I guess - you need to know the format of the json-string, the names of all fields and arrays......
It's parseJSONObject ?
yeah, I am on 3.0a5
I have moved to procesing version 2.2.1 and used your example and get the same error "the constructor JSONObject(Object) is not visible" when the constructor is called
json = new JSONObject(t1);
Undocumented method parseJSONObject() exists in Processing 2.2.1. No need for any alpha versions! ;)
Although I think its implementation is slower than it should be to say the least: :O)
Why instantiate a StringReader for a mere String?
IMO it makes more sense to directly create a JSONTokener from the String and pass it to the JSONObject: :-B
But then we get: "The constructor JSONObject(JSONTokener) is not visible"! X(
Even worse, the JSONTokener class itself isn't
public
norprotected
!!!Seems like the guys messing w/ the JSON stuff aren't friendly at letting their stuff
public
! >:PMost Processing's API are
public
or at leastprotected
.However this policy isn't being implemented to JSON code and it's locking us away! :-w
quote
as said
It's parseJSONObject !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
;-)
Thanks Chrisir, all working . Note to self, "try reading what somebody writes!"
that's a lesson....
but how about that... often I make a note on paper for a thing I have to do and next day I can't read it any more... because my hand-writing is too bad...
;-)