daniel gon
daniel gon

Reputation: 159

Put a integer in a json object in java

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

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

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

Upvotes: 0

Views: 963

Answers (3)

Nishant Bhardwaz
Nishant Bhardwaz

Reputation: 1001

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

The output is {"code":200}

Upvotes: 0

Edgencio Da Calista
Edgencio Da Calista

Reputation: 515

try using:

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

Upvotes: 0

nullPointer
nullPointer

Reputation: 4574

Use the put method instead :

objRes.put("code", 200);

Upvotes: 1

Related Questions