Hi guys, I was going to ask you to help me debug a program, but I already fixed it. So now I'll just ask for someone for more experienced in C# to explain why my original code didn't work but my new code does.
Originally I had this code which looks up "entries" in a dictionary and tries to store it in a List<Dictionary<string,object>> which entries actually was before I stored it as an object and then causes a null pointer exception when it reaches the foreach loop.
In this new code, I'm storing entries as an ArrayList which it never was and it works perfectly.
I'm new to C#, so if anyone has any insight into the language I'd be glad to hear it.
Originally I had this code which looks up "entries" in a dictionary and tries to store it in a List<Dictionary<string,object>> which entries actually was before I stored it as an object and then causes a null pointer exception when it reaches the foreach loop.
Dictionary<string,Object> json = new JsonParser(webpage).Decode() as Dictionary<string, object>; Object obj; bool b=json.TryGetValue("entries", out obj); List<Dictionary<string, object>> entries = obj as List<Dictionary<string, object>>; foreach(Dictionary<string,Object> entry in entries){ APIs.Add(new API(entry)); }
In this new code, I'm storing entries as an ArrayList which it never was and it works perfectly.
Dictionary<string,Object> json = new JsonParser(webpage).Decode() as Dictionary<string, object>; Object obj; bool b=json.TryGetValue("entries", out obj); ArrayList/*<Dictionary<string, object>>*/ entries = obj as ArrayList;//<Dictionary<string, object>>; foreach(Dictionary<string,Object> entry in entries){ APIs.Add(new API(entry)); }
I'm new to C#, so if anyone has any insight into the language I'd be glad to hear it.