Trying to decode a ds_map in a ds_list in a ds_map but the innermost map is completely empty.

J

jannycorp Inc

Guest


I don't know what I'm doing wrong. The size of the ds_list and "Total players connected" is correct, but when I try to decode the innermost map, it's entirely empty. Probably something incorrect on line 10.

If it helps, I am using this structure for network packets.
 

rytan451

Member
On line 9, you seem to have an extra semicolon (after n++)

On line 10, you're finding the contents of the list at index n. However, you're just printing out the keys of the map, then destroying the map. Where do you set the map?

Also, your code would be so much cleaner if you used accessors...
 
H

Homunculus

Guest
The innermost map doesn’t look right from the console output. Looks like you are adding the map to the ds_list as a string, instead of adding the actual map. Are you calling json_encode on the inner maps as well perhaps?

Your json should look like this:
{ "p": [ { "id": 34, "username": "hi reddit" } ] }

But instead you have this:
{ "p": ["{ \"id\": 34, \"username\": \"hi reddit\" }" ] }

You need to review how you generate the map.
 
Last edited by a moderator:

FrostyCat

Redemption Seeker
I don't know what I'm doing wrong. The size of the ds_list and "Total players connected" is correct, but when I try to decode the innermost map, it's entirely empty. Probably something incorrect on line 10.

If it helps, I am using this structure for network packets.
I've got it working, but it oddly required this extension: https://marketplace.yoyogames.com/assets/4328/tjson-better-json-functions
GMS sucks.
Quit blaming your tools. You don't have a map in a list in a map, you have a string in a list in a map. Big difference.

You can still use the built-in JSON parsing functions, but your inner loop would look like this:
Code:
for (var n = 0; n < ds_list_size(list); n++) {
  var map = json_decode(list[| i]);
  ...
  ds_map_destroy(map);
}
In the long run, I agree with Catan's conclusion. The API you're getting the JSON from is mangled, so you have a garbage-in-garbage-out problem. Fix it if you own it, or get another vendor if you don't own it.
 
J

jannycorp Inc

Guest
Thanks for the help but using the extension, it just works™ so :D
 
Top