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;
WebClient client2 = new WebClient();
client2.Headers.Add("Content-Type", "text/json");
client2.Headers.Add("X-Authorization", APIKey);
string result =
client2.DownloadString("https://xbl.io/api/v2/"+ XUIDGT +
"/presence");
var parse = JsonConvert.DeserializeObject<dynamic>(result);
string fin = parse["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.