Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wanted to load in map information using JSON, is there a way to get String, Int, float etc lists or arrays from JSON in Libgdx?

My structure looks like this

{
    "data": [{
        "name": "startmap",
        "actors": [{
            "name": "ryder"
        }]
    }]
}

And I want to get Actors as either a String List or Array, but there is no GetList or GetArray function. Is there any other way to do this?

share|improve this question

I have found the solution. First I add a JsonValue to my map object. Then I add a String list to my map object as well. JsonValue has this handy method called Child, wich allows me to loop through every child in the JsonValue, wich I add to my list of Strings.

The code looks like this.

newMap.actorstorage = saveJson.get("actors");
    for (JsonValue actor = newMap.actorstorage.child; actor != null; actor = actor.next){
        for(int c = 0; c < actor.size; c++){
            newMap.actors.add(actor.getString(c));
    }
}

Wich returns something like this

[name1,name2]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.