System.Exception at Json Parse
HRESULT: 0x83750007
System.Exception HResult=0x83750007 Message=Ungültige JSON-Zeichenfolge. (Exception from HRESULT: 0x83750007) Source=<Cannot evaluate the exception source> StackTrace: <Cannot evaluate the exception stack trace> |
For the UWP C # code
public async void read_API_Data() { //---------------< read_API_Data() >---------------
string sURL = "http://localhost:51198/api/projects"; HttpClient client = new HttpClient(); string sResponse = await client.GetStringAsync(sURL);
//*ERROR JsonObject jsonObject = JsonObject.Parse(sResponse); //---------------</ read_API_Data() >--------------- }
|
Solution:
If in the Asp.Net Core Api application a list is output as Json output, then the error 0x83750007 appears
You have to read a Json list in the client into a JsonArray and then go through the individual lines in a loop
JsonArray jsonArray = JsonArray.Parse(sResponse); foreach (var jsonRow in jsonArray) { //----< json Row >---- JsonObject jsonObject=jsonRow.GetObject(); .. {
|
public async void read_API_Data() { //---------------< read_API_Data() >--------------- //< read webApi > string sURL = "http://localhost:51198/api/projects"; HttpClient client = new HttpClient(); string sResponse = await client.GetStringAsync(sURL); //</ read webApi >
//< get Json values > JsonArray jsonArray = JsonArray.Parse(sResponse); foreach (var jsonRow in jsonArray) { //----< json Row >---- JsonObject jsonObject=jsonRow.GetObject();
//< values > string IDProject= jsonObject["idProject"].ToString(); string Title = jsonObject["title"].ToString(); string Text = jsonObject["text"].ToString(); string dtEdit = jsonObject["dtEdit"].ToString(); //</ values >
tbxResults.Text += Environment.NewLine + "-------"; tbxResults.Text += Environment.NewLine + "idProject=" + IDProject; tbxResults.Text += Environment.NewLine + "Title=" + Title; tbxResults.Text += Environment.NewLine + "Text=" + Text; tbxResults.Text += Environment.NewLine + "dtEdit=" + dtEdit; //----</ json Row >---- }
//</ get Json values > //---------------</ read_API_Data() >--------------- }
|