Getting array from Json suddenly doesnt work.
Hey guys, I have a project where I need to acess an API.However when I tried it, it gives me a NullreferenceException and I debugged it to see that the InnerPosts in Posts is null. Thus it breaks whenever I try to acess the InnerPosts.
The data is stored in a json array like this. 
{"posts" : [ { "data1" : "data", "data2" : "data"}, { "dataA" : "data", "dataB" : "data" } ] }
I know that it isnt implemented to get Json directly via JsonUtility so i wrapped it around. My Current class dedicated looks like this.
 [System.Serializable]
 public class Posts
 {
     public InnerPosts[] innerPosts;
 }
 [System.Serializable]
 public class InnerPosts
 {
     public string mediaUrl;
     public int postId;
     public int eventId;
 }
 
 public class ApiInfo 
 {
 
     public static Posts GetApiInfo(string Url)
     {
         var json = new System.Net.WebClient().DownloadString(Url);
         Posts postsArray = JsonUtility.FromJson<Posts>(json);
         return postsArray;
     }
 
 }
 
               It worked flawlessly the day before and I didnt really change anything that could have broken it, so instead of looking why it worked before and what was changed, I want to look into a better algorithm to get the Json correctly into my program. I can't use JavaScriptSerializer, it just doesnt work. Whenever I implement the namespaces necessary, Unity.lang stops working and I cant use it anymore. Any other way?
Answer by Firro · Feb 06, 2017 at 07:19 PM
Works now because of http://stackoverflow.com/a/36244111/7297857
Your answer
 
             Follow this Question
Related Questions
Assigning to array give NullReferenceExecption!?!! 0 Answers
(SOLVED) Accessing (string) arrays by enumerations from another class 0 Answers
Null reference exception in an if statement that checks for it. 1 Answer
My Script Won't Let Me Castle C# Chess 0 Answers
JsonUtility and Arrays - JSON must represent an object type. 0 Answers