Search Unity

Help with JSON/simpleJSON and arrays would be appreciated.

Discussion in 'Scripting' started by monkeybrother, Nov 26, 2013.

  1. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    Hi. I need to pass JSON-data to unity through a text file. I've been using simpleJSON and I've got the data into unity the way I want it, but I just can't find an easy way of looping through/accessing or finding specific keys in the JSON object, which I need to do often.

    So, my question is, how can I "translate" the JSON-object to a standard multidimensional associative JS list/array (I get confused, I've been learning JS, PHP and Python simultaneously) so that it's easier to use? I'm not a complete noob, but the "object" part in "object oriented" is still largely a mystery to me.


    Here's the JSON data I've been testing with:

    Code (csharp):
    1. {
    2. "Apple": {
    3.     "ingameName" : "Apple",
    4.     "description": "This sure is an apple",
    5.     "action": "options",
    6.     "options": {
    7.         "lick_apple" : {"action" : "none", "comment" : "Tastes like pesticides"},
    8.         "eat_apple" : {"action" : "remove", "comment" : "It just vanished"},
    9.         "steal_apple" : {"action" : "take", "comment" : "I took that apple good"} },
    10. },
    11. "Kontorsstol": {
    12.     "ingameName" : "Kontorsstol",
    13.     "description": "It looks pretty uncomfortable",
    14.     "action": "push",
    15.     "actionParameter": 500
    16. },
    17. "Treasure": {
    18.     "ingameName" : "Treasure",
    19.     "description": "This is the prettiest treasure I've seen",
    20.     "action": "take",
    21. }
    22. }

    Any help appreciated.
     
  2. monkeybrother

    monkeybrother

    Joined:
    Oct 14, 2010
    Posts:
    83
    Anybody? I'm basically only looking for a way to get JSON data into a regular array.