1. Hey! Guest! The 34th GMC Jam will take place between August 22nd, 12:00 UTC (Thursday noon) and August 26th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

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

Discussion in 'Programming' started by jannycorp Inc, Aug 14, 2019.

  1. jannycorp Inc

    jannycorp Inc Member

    Joined:
    Jul 4, 2019
    Posts:
    3
    [​IMG]

    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.
     
  2. jannycorp Inc

    jannycorp Inc Member

    Joined:
    Jul 4, 2019
    Posts:
    3
  3. rytan451

    rytan451 Member

    Joined:
    Jun 21, 2016
    Posts:
    50
    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...
     
  4. Catan

    Catan Member

    Joined:
    Jun 20, 2016
    Posts:
    651
    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: Aug 14, 2019
  5. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,327
    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.
     
  6. jannycorp Inc

    jannycorp Inc Member

    Joined:
    Jul 4, 2019
    Posts:
    3
    Thanks for the help but using the extension, it just works™ so :D
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice