Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

(Some) End users experiencing json parsing errors

Discussion in 'Scripting' started by Vertnacular, May 27, 2020.

  1. Vertnacular

    Vertnacular

    Joined:
    Oct 15, 2017
    Posts:
    12
    So I have my game released and I'm getting a small number (actually only 2) people saying that they're receiving errors. The weird thing is that I had the game tested on a number of computers by several other people, tested on 4 computers myself, and no other players are experiencing this issue.

    From these player's reports from an in game console, it seems to be an issue with the json parser. I'll back up a bit and explain that my game loads a bunch of info at start from a series of json files and some assets from from the addressables system. I wrote a bit of a more generalized system on top of the c# json utilities that tries to convert strings to a given data type using convert.changetype. I should mention I also rewrote this load system completely. Originally when these players made the claim, the system used the json utilities with specific serialized classes so there was no convert method.

    At first I was thinking that their system was having an issue with loading the files due to a permissions thing with their computer. Or maybe something with an anti-virus blocking access to the files. Actually one tester had this exact problem and was easily fixed, but the players claim that all the permissions are set correctly. This also can't be the issue due to the fact that I actually put in in a fail-safe system that tries to load these files and tries to parse them but if it can't, then it defaults to a script that actually holds all these hard coded values. Apparently the try/catch is not defaulting to that system.

    The next thing I was thinking was maybe the json utilities or convert.changetype has some sort of redistributables issue. I know Unity doesn't need redistributables, but it was a long shot. Maybe some functionality was missing. Of course this wasn't the issue.

    I'm really not sure why these users are experiencing these issues. Like I said, the system should work and does for 99.999999% of users and should fail safe if it doesn't. I was wondering if anyone might have some insight based on this info?
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    What data are you reading and what country are the problematic users from? For example in germany "," (comma) is used for decimal delimiter. Maybe there are also issues with " ' " and such characters. So it would be good to show an example of the data you import and ask the users what their region (in operating system) is set to. And I don't know how this affects Unity. It's just a shot in the dark but I had serious issues with this when importing scientific data from different regions of the world many years back. So it could be worth investigating.
     
  3. Vertnacular

    Vertnacular

    Joined:
    Oct 15, 2017
    Posts:
    12
    So It looks like this. The data is split by a ":" the first part is used as a key, the second gets converted.

    Code (CSharp):
    1. "flavorName:Old Water",
    2. "tasteValue:-0.1",
    3. "flavorStrength:0.05"
    This would be very interesting if this is the case. I guess I'll investigate a way to convert or set culture info when deserializing. If anyone off hand knows about doing that, please let me know.

    Thanks!
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,773
    That's not JSON. JSON for that data would look like:
    Code (csharp):
    1. "flavorName":"Old Water",
    2. "tasteValue":-0.1,
    3. "flavorStrength":0.05
    I mean, I guess if it's an array of strings and you're manually parsing the strings, sure it's valid JSON, but why would you be doing that instead of just using the JSON for what it's good at...? (If you retyped that from memory..... don't do that, as you'll almost certainly unknowingly change things while doing so and either introduce new problems, or subsciously fix the actual problem. It makes it really hard to help. Please copy and paste the actual, exact JSON text from a JSON file)

    We need to see your code, we need the actual error message, and we need to see the actual full JSON file that triggers the issue, if you can possibly get that from your users having the problem. I'm not sure how you expect us to be able to help without any of those things.
     
  5. Vertnacular

    Vertnacular

    Joined:
    Oct 15, 2017
    Posts:
    12
    It's cool dude, exiguous had the exact experience and insight I was looking for. It's seems to be the whole "," vs "." issue. And I believe I just need to change the CultureInfo in Globalization and force it to use an "en-US" as a standard. Thanks again!