question

sharathhere avatar image
sharathhere asked

Json format for title data: Compatable with Unity

Hi, I was trying to go through PlayFab yesterday (mainly through Title Data). I tried uploading my game's Json (Both the formats listed below) and it didn't process, giving me an error message "There was an error parsing your file. Please check your JSON syntax.". The Json we use is the one recommend for unity. Please check the below Json and let me know.

Also please give me a sample json in which I can store data like the below formats.
Format 1:
{
"GunsList": [
{
"GunName": "AK47",
"GunDescription": "Machine Gun",
"Range": "42",
"MagCapacityUpgradeValues": [
"50",
"150",
"250",
"450",
"200",
"0"
]
"UnlockLevel": "0"
},
{
"GunName": "Colt",
"GunDescription": "Pistol",
"Range": "35",
"MagCapacityUpgradeValues": [
"47",
"94",
"111",
"111",
"0",
"0"
]
"UnlockLevel": "0"
},
]
}

Format 2:
{
"GunsList":
{
"GunName": "Vickers",
"GunDescription": "Machine Gun Vickers",
"Range": "42",
"ReloadSpeed": "1",
"ShieldOption": "1",
"APAmmo":"1",
"Tracer":"1",
"Explosive":"1",
"OverheatPerShot":"1",
"GunDisabledDelay":"1",
"CoolDownPerSecond":"1",
"UnlockLevel": "0"
}
}
unity3dTitle Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

JSON isn't platform-specific - it's an open standard. So, there should be no "Unity version" of JSON at all. What we have noticed over the years is that different parsers have minor differences - the most notable being whether or not they allow a comma on the last element in a list/array.

There are a number of JSON validators available online that you can use to check your data (ex: https://jsonlint.com/?json=). In your case, the first of your formats is invalid as it is missing a comma just before each UnlockLevel, and it has an extraneous comma near the end. Your format 2 is fine, though - and it saves without any errors when I try it in my test title. How specifically are you trying to save it? As "GunsList" for the Key and the rest as the Value? Or with the whole thing being the Value and something else as the Key? If you can provide specifics on how you're trying to save it, we should be able to spot the issue you're having.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

sharathhere avatar image sharathhere commented ·

Sorry, I didn't notice that error in the 1st eg.

We are trying to save it with both keys and values. There will be mutiple and mutidimentional arrays in the json.

So for the below json

{
"GunsList": [{
"GunName": "AK47",
"GunDescription": "Machine Gun",
"Range": "42",
"MagCapacityUpgradeValues": [
"50",
"150",
"250",
"450",
"200",
"0"
],
"UnlockLevel": "0"
},
{
"GunName": "Colt",
"GunDescription": "Pistol",
"Range": "35",
"MagCapacityUpgradeValues": [
"47",
"94",
"111",
"111",
"0",
"0"
],
"UnlockLevel": "0"
}
]
}

I am trying to get a category of title Data which deals with just gun details. So that, when I pull this json from your server we get all information about all guns in that json. And also its easy to edit / tweak the required data in it through your front end.

The different guns will be different arrays and some elements which hold multiple values will result in a nested array inside it.

0 Likes 0 ·
brendan avatar image brendan sharathhere commented ·

Sounds good - let us know if you run into any issues.

0 Likes 0 ·
sharathhere avatar image sharathhere brendan commented ·

Actually the problem still persist :). I am not able to upload the json in title data. It says - "There was an error parsing your file. Please check your JSON syntax."

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.