Search Unity

Bug Product receipt JSON badly formatted [UnityIAP 4.4.1, 4.5.2 and 4.6.0]

Discussion in 'Unity IAP' started by MatijaZorboski, Mar 10, 2023.

  1. MatijaZorboski

    MatijaZorboski

    Joined:
    Feb 24, 2021
    Posts:
    4
    We recently encountered an issue when parsing JSON data from UnityIAP. Specifically, we noticed that if a product description has new line characters at the end of it, our system crashes on parsing this kind of data.

    For example, consider the following JSON snippet:

    Code (JavaScript):
    1. \\\"skuDetails\\\":
    2. [\\\"
    3. {
    4. \\\\\\\"productId\\\\\\\":\\\\\\\"xxxxxxxxxxx\\\\\\\",
    5. \\\\\\\"type\\\\\\\":\\\\\\\"inapp\\\\\\\",
    6. \\\\\\\"title\\\\\\\":\\\\\\\"Golden Coins Pack (xxxxxxxxxxx)\\\\\\\",
    7. \\\\\\\"name\\\\\\\":\\\\\\\"Golden Coins Pack\\\\\\\",
    8. \\\\\\\"description\\\\\\\":\\\\\\\"Golden Coins Pack\\\\\\\\\\\\\\",
    9. \\\\\\\"price\\\\\\\":\\\\\\\"RSD\\\\u00a0xxxxxxxxxxx\\\\\\\",
    10. \\\\\\\"price_amount_micros\\\\\\\":xxxxxxxxxxx,
    11. \\\\\\\"price_currency_code\\\\\\\":\\\\\\\"xxxxxxxxxxx\\\\\\\",
    12. \\\\\\\"skuDetailsToken\\\\\\\":\\\\\\\"xxxxxxxxxxx\\\\\\\"
    13. }\\\"
    14. ]
    15. }\",
    and example of description for that case:

    Code (CSharp):
    1. Golden Coins Pack
    2.  
    In this case you can notice that there is an extra set of escape characters in the description which causes problems with parsing. Instead of
    \\\\\\\
    it has
    \\\\\\\\\\\\\\

    We had a problem that Singular crashes when parsing this kind of JSON, and it created a big problem in our UA campaigns as IAPs with new line character in description where not registered by Singular. We reproduced the problem in versions 4.4.1, 4.5.2 and 4.6.0.
     
  2. Yannick_D

    Yannick_D

    Unity Technologies

    Joined:
    Feb 21, 2022
    Posts:
    231
    Hello MatijaZorboski,

    We have done some tests to attempt to reproduce the same situation you have, but we are not getting the same result.
    For the description, we get the following from the Google Play Store:
    \"description\":\"Golden Coins Pack\\n\"

    Once we transform it into Json, we obtain the following in the product.receipt:
    \\\"description\\\":\\\"Golden Coins Pack\\\\n\\\"

    In our tests, we always have the `\n`, but it seems to be missing in your case.
    Could you give us more information on where you are obtaining the receipt and what manipulations you are applying to it?