c# - How to put variable into JSON -


actually i'm working pushsharp. send notification have put variable json instead of hardcoded text (below example).

var msg = "test message";     push.queuenotification(new gcmnotification().fordeviceregistrationid(registrationid)                              .withjson("{\"alert\":\"here message\",\"badge\":7,\"sound\":\"sound.caf\"}")); 

is possible? how can put msg variable

i tried this:

push.queuenotification(new gcmnotification().fordeviceregistrationid(registrationid)                          .withjson("{\"alert\":\"{0}\",\"badge\":7,\"sound\":\"sound.caf\"}",msg)); 

but says: no overload method 'withjson' takes '3' arguments.

any idea's how solve problem?

if want add message json this:

var msg = "my message"; // set somewhere else in code var jsonobject = {     "alert" : "{0}",     "badge" : "7",     "sound" : "sound.caf",     "msg" : msg };  // convert object string var jsonstring = json.stringify(jsonobject);  push.queuenotification(new gcmnotification().fordeviceregistrationid(registrationid)         .withjson(jsonstring)); 

edit: changed code don't have manipulate string. instead can manipulate jsonobject. json.stringify converts string then.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -