- Home /
SimpleJSON get Array lenght ?
Hello, i just begin in Unity and C# from a week and i'm facing an issue using the SimpleJSON.
Here is my JSON Scenario in .txt :
{
"Intro": {
"1": [
"Lina","Salut toi","Happy"
],
"2": [
"Alphonse","Oui et toi","Happy"
],
"3": [
"Lina","Tres bien","Normal"
],
"4": [
"Alphonse","Cool","Happy"
]
"5": [
"Alphonse","What'up now ?","Questionning"
]
"6": [
"Alphonse","On va manger au resto ?","Questionning"
]
}
}
And here the method i use to get what's in each part of my storyline :
using SimpleJSON;
public static JSONNode testData;
public static TextAsset filejson;
public static string fileNamejson = "";
public static void define_scenario_lenght()
{
string EventNumber = Regex.Replace(Event_Collider.EventColliderName.ToString (), "[^0-9]", "");
fileNamejson = "Text_JSON/STORY/STORY_JSON_FR";
filejson = (TextAsset) Resources.Load(fileNamejson);
testData = JsonParser(filejson.text);
Debug.Log ("Contenu du Scenar = "+testData.ToString()); //WORK
Debug.Log ("Taille de L'intro = "+testData["Intro"][0]);
// WORK
Debug.Log ("Scenario Intro Length = "+testData["Intro"].length);
// Don't work because there is no Length define
So i wanna know if there is a way to get the Lenght of my JSON array ?
I mean get ["Intro"] lenght for instance, because i will dynamically add values in it, so i can't rely on a fix number. (sorry for my crappy english xd).
Answer by Bakunyan · Feb 16, 2014 at 06:29 PM
Hum i figured a temporary solution adding at each scenario's part this :
"0": [
"Lenght","7",""
],
But its not dynamic if i'm adding new text in parts after, i have to manually to it, but at least it work^^.
Your answer

Follow this Question
Related Questions
JSON missing arrays 1 Answer
JsonUtility not working with Arrays 2 Answers
Get JSON array object string value 2 Answers
Instantiate a prefab from jsonarray? 1 Answer
How to slice JsonData Array in unity? 0 Answers