0

I want this {"code":200} and try

objRes = new JSONObject();
objRes.append("code", 200);

but forms {"code":[200]} instead {"code":200}

2
  • objRes.("code", 200); don't you forgot the method name ? the lintax looks odd Commented Mar 8, 2019 at 14:00
  • 5
    Which of the dozens of JSONObject classes are you using? Which package, which library? Have you read its javadoc? Where is it located? Commented Mar 8, 2019 at 14:01

3 Answers 3

1

Use the put method instead :

objRes.put("code", 200);
Sign up to request clarification or add additional context in comments.

Comments

0

try using:

JSONObject objRes = new JSONObject ();
objRes.put("code", 200);

Comments

0
 final JSONObject ref = new JSONObject();
 ref.put("code", 200);

The output is {"code":200}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.