Click here to Skip to main content
15,741,391 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So I am currently working on a Xbox API but having a issue with the parse. It throws this error "
System.ArgumentException: 'Accessed JArray values with invalid key value: "state". Int32 array index expected.'
", any help I will be very grateful :)

xuidTB.Text = XUIDGT;  
                //Grab Status
                WebClient client2 = new WebClient();
                client2.Headers.Add("Content-Type", "text/json");
                client2.Headers.Add("X-Authorization", APIKey);
                string result = 
               client2.DownloadString(""+ XUIDGT + 
                var parse = JsonConvert.DeserializeObject<dynamic>(result);
              string fin = parse["state"].ToString();
              // string fin = JObject.Parse(result)["state"].ToString();
               string de = fin.Replace("\"", "");
                StatusTB.Text = de;

What I have tried:

I have tried using the JObject "
string fin = JObject.Parse(result)["state"].ToString();
" but this also throws a error stating
Newtonsoft.Json.JsonReaderException: 'Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.'

I can see it grabbing all the data whiles hovering over the result so I assume it the way I am trying to pull it to the textBox. I do apologise for any grammar issue or bad explaining English is it not my main language.
Richard MacCutchan 1-May-23 8:30am    
At a guess your code is not getting a valid Json array. So use the debugger to see exactly what is being received in your code.
Graeme_Grant 1-May-23 8:43am    
Please post the JSON so we can see what you are decoding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900