1

I have a JSONObject:

JSONObject data = new JSONObject("{\"alert\": \"The Mets scored!\", \"action\": \"com.vipulk.acuv.UPDATE_STATUS\",\"ph\": ph }");

I have a string defined as:

     String ph="this is String";

Now when i receive this JSONObject on receiver side I have the value of "ph" as "ph". I want the value of original String ph. How to do it. Can JSONObject send extra strings with another method.

Pardon my limited knowledge about JSON, as I am using it just once so I am avoiding going deep. I have everything done except putting this string variable in JSONObject.

NOTE: I am working with PARSE push notifications and I've to send this object in a push notification (that i am able to do).

1
  • What do you mean by I have the value of "ph" as "ph" ? Commented Feb 11, 2014 at 9:03

1 Answer 1

4

If you want to modify your JSONObject, you can use .put method (http://json.org/javadoc/org/json/JSONObject.html#put%28java.lang.String,%20java.lang.Object%29):

data.put("ph", ph);
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks. That worked. I wasn't sure about using .put method. As there wasn't any mention of putting a string value in the docs (none that I could find)
Why that didn't work for me? JSONObject Customer= new JSONObject(); Customer.put("name",name);
Is it just an error in the Android documentation that there is no mention of putting a String into a JSON object? developer.android.com/reference/org/json/JSONObject

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.