Skip to main content

On Sale: GamesAssetsToolsTabletopComics
Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

How to deal with nested object.

A topic by k3nn created Dec 07, 2019 Views: 320 Replies: 2
Viewing posts 1 to 3

Hello Vadim,

I got something like this. How do i access values inside obj1 and obj2?

{
   "obj1":{
      "item1":["w","s","a","d","i","o","p","k"],
      "item2":["-1","-1","-1","-1","-1","-1","-1","-1"],
      "item3":["-1","-1","-1","-1","-1","-1","-1","-1"],
      "item4":["-1","-1","-1","-1","-1","-1","-1","-1"]
   },
   "obj2":{
      "item1":["-1","-1","-1","-1","-1","-1","-1","-1"],
      "item2":["-1","-1","-1","-1","-1","-1","-1","-1"],
      "item3":["-1","-1","-1","-1","-1","-1","-1","-1"],
      "item4":["-1","-1","-1","-1","-1","-1","-1","-1"]
   }
}

Developer(+1)
var root = tj_decode(...);
var obj1 = tj_get(root, "obj1");
var item1 = tj_get(obj1, "item1");
var w = item1[0];

Thanks Vadim! Its easier than i thought.