How to create JSONObject?


(Claudio) #1

Hi Folks,
I have a question: How can you create a JSON object within a extension?
If I use the code

JSONObject jObject = new JSONObject(jsonString)

where jsonString is the json text I want to create the object from, I get an error at jsonString about incompatible type (incompatible types: String cannot be converted to ComponentContainer).
Any thoughts?
Cheers,
Lildinti


#2

Hello.
Have you import all librarys?
On stackoverflow.com you can find the most answers.


(Claudio) #3

Hi Mika!
Thanks for you kind reply and apologies for the late reply to you but had some family problems and just coming back to work.
Anyway, my question is can I use these import in the IDE?

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

The compiling logs show these lines:

AndroidRuntime:
[mkdir] Created dir: /home/Makeroid/appinventor/components/build/classes/AndroidRuntime
[javac] Compiling 316 source files to /home/Makeroid/appinventor/components/build/classes/AndroidRuntime
[javac] warning: [options] bootstrap class path not set in conjunction with -source 1.7
[javac] /home/Makeroid/appinventor/components/src/com/google/appinventor/components/runtime/JSONObject.java:16: error: package org.json.simple does not exist
[javac] import org.json.simple.JSONArray;
[javac] ^
[javac] /home/Makeroid/appinventor/components/src/com/google/appinventor/components/runtime/JSONObject.java:17: error: package org.json.simple does not exist
[javac] import org.json.simple.JSONObject;
[javac] ^

What makes me think the JSON libs are not imported.

Thank you so much for any help and again, apologies for the late reply.
Cheers
Lildinti


#4

Not sure why you can’t use the libs.
They should be there for useage.

@Diego Can you look if the sources are up to date?
There is still makeroid as folder name.


(Diego Barreiro Pérez) #5

Yeah, they are
I’ll take a look anyway to it this afternoon


(Claudio) #6

Thank you heaps, guys!
Cheers,
Lildinti