- Home /
Question by
Kamuiyshirou · Aug 05, 2017 at 01:23 PM ·
c#objectjsonwwwform
How to get an object inside a json JsonUtility
I have the following code and I need to get and traverse the object called DATA:
[Serializable]
public class Player
{
public string[] data;
}
.....
string jsonString = "{ \"status_code\":200,\"data\":{ \"id\":10,\"name\":\"Big Head 50\",\"email\":\"teste@teste.com.br\",\"token\":\"KkR8eLPHQ7\",\"status\":true,\"role\":\"teste\",\"avatar\":\"/uploads/users/e6DQUmfvkq1q.jpg\",\"phone\":\"(55) 95555-5555\",\"dob\":\"1991-01-26\",\"gender\":1,\"mobile_phone\":\"(44) 94444-4444\",\"whatsapp\":\"(99) 99999-9999\"} }";
Player player = (Player)JsonUtility.FromJson(jsonString, typeof(Player));
Debug.Log(player.data);
Error: Unexpected node type.UnityEngine.JsonUtility:FromJson(String, Type)
In LOG: System.String[] UnityEngine.Debug:Log(Object)
json
:
{
"status_code":200,
"data":{
"id":10,
"name":"Big Head 50",
"email":"teste@gmail.com.br",
"token":"eyJ0e",
"status":true,
"role":"teste",
"avatar":"\/uploads\/users\/e6DQUmfvkq1q.jpg",
"phone":"(55) 95555-5555",
"dob":"1991-01-26",
"gender":1,
"mobile_phone":"(44) 94444-4444",
"whatsapp":"(99) 99999-9999"
}
}
...
Comment
Your json string does not seem to be valid. Did you write it yourself?
Your answer
![](https://koobas.hobune.stream/wayback/20220612132009im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting data out of Dictionary 0 Answers
Distribute terrain in zones 3 Answers
Using Json to store data for objects 1 Answer
Multiple Cars not working 1 Answer
Instantiate a prefab from jsonarray? 1 Answer