-1

This is my method/function:

public static Object testFunction (String GoesHere)

I'm not sure how to reference the object as I've checked its syntax and seems to be written correctly, but it does not have a name. Also, it's of type and the method/function is expecting a string. Thanks so much

Kevin Wei
  • 165
  • 11

2 Answers2

0

Since it is in Json format, you can just refer that as a Json String

String jsonString =  JSONObject.escape(yourRawString);

The type of JSONObject is org.json.simple.JSONObject

Then pass it to testFunction(jsonString)

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
  • Can you give me an example of setting yourRawString to some JSON code? Thanks, I've tried that and it's giving me errors – Kevin Wei Dec 24 '15 at 07:45
  • @HaroldFinch You have to escape the quotes – Suresh Atta Dec 24 '15 at 08:06
  • Yes I tried not using quotes and I'm getting an error. Here's a screenshot: http://imgur.com/UwDmbCT – Kevin Wei Dec 24 '15 at 08:09
  • I am started with an '{'. I also don't want everything to be on the same line because I want to parse this later and will take advantage of the fact it has new lines. – Kevin Wei Dec 24 '15 at 08:12
0

This way you can use JsonObject. This is the best way to create the json object and use.

JSONObject jsonObject= new JSONObject();
jsonObject.put("radio","on");

If you want String after creating just call this method.

jsonObject.toString();
Giriraj
  • 21
  • 4
  • Hi thanks, but it says cannot resolve JSONObject. I tried this but it's not working: import org.json.simple.JSONObject; – Kevin Wei Dec 24 '15 at 08:16
  • Yes you should import the package.Check if you have that package otherwise download and use it.@HaroldFinch – Giriraj Dec 24 '15 at 08:26
  • Hi thanks I successfully imported that, but now it's saying cannot resolve symbol "put" – Kevin Wei Dec 24 '15 at 08:53