I am new to unity, i am learning how to make a unity app with Facebook integration using the Facebook SDK for Unity. I have been trying to make a json result from a graph request that is executed in a class method from unity, my problem is that everytime i try to access a propery of the supposed deserialized json to class it throws this error:
Object reference not set to an instance of an object
This error is thrown at the line where i am trying to access the property and not where the object is created.. this happens with both json utilities from Facebook and Unity, i've no idea how to properly transform a json data into a class, the code i have is this:
private void FbGetPhotos() {
actionText.text = "Requesting photos";
FB.API("/me/photos", HttpMethod.GET, result => {
NodesResult nodesResult = NodesResult.FromJSON(result.RawResult);
Debug.Log(nodesResult.data.Count);
});
}
NodesResult class
using System.Collections.Generic;
using UnityEngine;
namespace classes {
public class NodesResult {
public List<object> data;
public object paging;
public static NodesResult FromJSON(string raw) {
return JsonUtility.FromJson<NodesResult>(raw);
}
}
}
JSON String
{
"data": [
{
"created_time": "2018-08-12T08:07:35+0000",
"name": "Horas de horas para lograr esto Javier Andres Mura Rios Estoy orgulloso.",
"id": "1919500911450147"
}
],
"paging": {
"cursors": {
"before": "QVFIUnpNaTZAqSW1NMDJya0ZAtWUZAiRWxRWW1lUHdmYy1rVERHaldsVllXSFBab0h4YW1HcEtXTmhNdW0tNGxVVjRQbXotdHo3alBvUzRUa09TaVJiVzJYc2ln",
"after": "QVFIUnpNaTZAqSW1NMDJya0ZAtWUZAiRWxRWW1lUHdmYy1rVERHaldsVllXSFBab0h4YW1HcEtXTmhNdW0tNGxVVjRQbXotdHo3alBvUzRUa09TaVJiVzJYc2ln"
}
}
}
Like i said, the error is thrown when i try to access the property, in this case is where the Debug.Log is.
Note: I know there are many examples out there but none of them worked for me, also the facebook example handles the data using Dictionary object only, but i believe that using Dictionary only would make the code a bit hard to understand, also this is likely my first time parsing a json string in C# so i am very interested on what is the recommended way to properly parse the json string into a class and sub-classes