Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSONObject.put(string,string) not working

String value = myInput.getText().toString();

I want to put string value into JSONObject.put("STRING",value) method but it's not working..

See the attached screen shot and tell how to resolve this.

enter image description here

like image 326
Kamal Oberoi Avatar asked Mar 24 '26 11:03

Kamal Oberoi


1 Answers

Add try.. catch

String data = "";
String val = "hello";
            try {
                JSONObject j = new JSONObject(data);
                j.put("VAL", val);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
like image 141
Sathish Kumar J Avatar answered Mar 27 '26 00:03

Sathish Kumar J



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!