# Still having problems using Json data in Unity

I have the following classes and json file, i thought id followed the documentation exactly but I am clearly wrong. Can anyone see why I get an error just saying : INVALID VALUE in my unity console:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

[Serializable]
{
public float[] x;
public float[] y;
public float[] z;
}


GameController:

public class GameController : MonoBehaviour { public static GameController instance;

DataReader dataReader;

private string gameDataFileName = "level1.json";

private void Awake()
{
instance = this;
}

void Start () {

// create level:
}

}


and the json is stored in StreamingAssets folder (I also tried a copy in Resources folder):

{
"x": [{1},{1},{1},{1}],
"y": [{1},{1},{1},{1}],
"z": [{1},{2},{3},{4}]
}


Remove the curly braces from your values.

{
"x": [1,1,1,1],
"y": [1,1,1,1],
"z": [1,2,3,4]
}


Though I'd also recommend for sanity sake to group by point and not by axis.

[Serializable]
public class Point
{
public float x;
public float y;
public float z;
}

[Serializable]
{
public Point[] points;
}

{
"points": [
{
"x": 1,
"y": 1,
"z": 1
},
{
"x": 1,
"y": 1,
"z": 2
},
...
]
}

• thanks again Chris, you have solved my incorrect syntax inside the json and I now understand how they are to be completed. But unfortunately I still have the vague error message of : Invalud Value in Unity. – Big T Larrity Aug 15 '17 at 17:38
• try changing the numbers to 1.0 or 1.0f or "1.0f". Unity needs to know that the numeric constant is a float and not an integer. – Chris Aug 15 '17 at 17:41
• just letting you know i fixed it finally. I needed to make a TextAsset tohold the json name string. Ive posted the full code as another answer for anyone who is confused the same as me in future – Big T Larrity Aug 15 '17 at 20:18
public class GameController : MonoBehaviour {
public static GameController instance;

TextAsset textAsset;

List<float> xList = new List<float>();

private void Awake()
{
print("JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJSON = " + textAsset.text);

instance = this;
}

void Start () {
// this just requests the ad, doesnt show it:

for (int i = 0; i < dataReader.x.Length; i++)
{

}
// create level:
print("DATA: " + xList[0]);
}

void Update () {

}


}

This code fixed it. I was missing the TextAsset taht whats confused me the whole time.