I am using Pushwoosh together with Unity and are happy to do so. Recently I have found the need to send custom data through my pushes, but am unsuccessful in handeling them.

I am sending the push from within my Unity like this:

    string gameJsonString = "{“gameid”:”"+GameData.ObjectId+"”}";

    string postScoreURL = "https://cp.pushwoosh.com/json/1.3/createMessage";
    string jsonString = "{\"request\":{\"application\":\"myPWAppId\",\"auth\":\"MyAuthHere\",\"notifications\":[{\"send_date\":\"now\",\"ios_badges\":\"1\",\"devices\":\"SomeToken\",\"content\":\"Doing a tes for this\",\"data\":{\"custom\":\""+gameJsonString+"\"},\"link\":\"\",\"minimize_link\":0,\"ios_sound\":\"alert.mp3\"}]}}";
    System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

    Dictionary<string, string> postHeader = new Dictionary<string, string>();

    postHeader.Add("Content-Type", "text/json");
    postHeader.Add("Method", "POST");
    postHeader.Add("Content-Length", ""+jsonString.Length);

    print("jsonString: " + jsonString);

    WWW request = new WWW( postScoreURL, encoding.GetBytes(jsonString), postHeader);
    yield return request;

    // Print the error to the console
    if (request.error != null)  
        Debug.Log("request error: " + request.error);   
        Debug.Log("request success");
        Debug.Log("returned data" + request.data);  

The Push gets send perfectly, but when i try to handle payload (I want to get the gameid sendt from gameJsonString) im have no luck :-(

This is what I receive:

    "aps": {
        "badge": 1,
        "sound": "alert.mp3",
        "alert": "Somthing here"
    "u": "{
        \"custom\": \"{
            \"gameid\": \"12345\"

First of all, this is not a valid jsonstring. How come I get an invalid jsonstring from the PW server?

I then try to make it valid like this with SimpleJSON:

void onPushNotificationsReceived(string payload)
    payload = payload.Replace("\\", "");
    payload = payload.Replace("\"{", "{");
    payload = payload.Replace("}\"", "}");

    var N = JSON.Parse(payload);
    var gameData = N["u"]["custom"];

    print ("Whats in U: "+gameData["gameid"].ToString());

This does not solve it... What to do?

Any help is appreciated and thanks in advance.

asked 20 Aug '15, 13:55
jmansa's gravatar image


Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 20 Aug '15, 13:55

question was seen: 844 times

last updated: 20 Aug '15, 13:55