Convert Http response to JsonObject

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Devops
Posts: 23
Joined: 27 May 2020, 15:23

Convert Http response to JsonObject

Postby Devops » 16 Jun 2020, 08:51

I am getting a JSON response in the HTTP api call which is made from smartfox.
I want this data to be converted into JSON in smartfox extension so that I can access the data from the response.

Code: Select all

         JSONObject jsonObj = new JSONObject(jsonString);


I am trying to convert the jsonString to object using the above line.

This is how the conversion works in java as per multiple sources but in smartfox I am getting following error :

Code: Select all

java.lang.NoClassDefFoundError: org/json/JSONObject


What is causing the issue here? Why do we need class to convert into JSON?
User avatar
Lapo
Site Admin
Posts: 23025
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Convert Http response to JsonObject

Postby Lapo » 16 Jun 2020, 09:33

From the error it looks like you're referencing an org.json.JSONObject class, but this class doesn't exist in the default SFS2X classpath. It requires a new library to be downloaded and added to the classpath.

However, SFS2X already comes with a JSON library.
http://json-lib.sourceforge.net/apidocs ... mmary.html

To deserialize from a String:

Code: Select all

JSONObject jso = JSONObject.fromObject(jsonStr);


So you have two options:

1) Use the JSON lib we already provide
2) Download and add the org.json package to the SFS2X classpath.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 63 guests