clugg / sm-json

A pure SourcePawn JSON encoder/decoder.
GNU General Public License v3.0
82 stars 8 forks source link

json_decode: expected key string at position 1 #7

Closed joao-mambelli closed 4 years ago

joao-mambelli commented 4 years ago

So, I'm trying to decode a josn HTTP Response retrieved using SteamWorks and I get this message: json_decode: expected key string at position 1.

I saw the include files and saw that it was expecting a double quotes at the position 1... I don't see what I'm doing wrong here... Any help?

The json I'm trying to decode with some information hidden:

{'name': 'MY TEST', 'mp_maxrounds': 30, 'bo': 1, 'maps': ['aim_glockon', 'aim_map', 'aim_map2_go', 'aim_redline', 'awp_bridge', 'awp_map_classic', 'fy_poolparty_go', 'scoutknifez'
    ], 'maxplayers': 4, 'tournament_id': 'test', 'bracket': {'id': 'test', 'participants': {'test': {'name': 'test', 'players': [
                    {'name': 'test', 'steamId64': 'test', 'captain': False
                    },
                    {'name': 'test', 'steamId64': 'test', 'captain': True
                    }
                ]
            }
        }, 'server_config': {'mp_overtime_enable': 2, 'mp_overtime_maxrounds': 6, 'tv_delay': 5, 'bot_quota': 0, 'mp_friendlyfire': 1, 'tv_enable': 0, 'mp_freezetime': 15, 'mp_halftime_duration': 30, 'sv_deadtalk': 0, 'sv_alltalk': 0, 'sv_prime_accounts_only': 0
        }
    }
}

Code:

JSON_Object json = new JSON_Object();
json.Decode(body);
joao-mambelli commented 4 years ago

Ok, so as I’m a newbe in relation to json, I just figured out that single quotes are wrong with json... The problem is with the api itself...

clugg commented 4 years ago

As a late update to this issue, I have just added optional support for parsing strings with single quotes, in case you happen to still be working with a malformed API. This is available as of v2.2.0 and you can check the README for instructions to enable this option.

joao-mambelli commented 4 years ago

That’s very handy, thanks