Domanda

Ottengo una stringa di risposta da un'API utilizzando questo codice:

HttpResponseMessage response = await client.GetAsync(url);
string responseText = await response.Content.ReadAsStringAsync();
.

Comunque non riesco a scoprire come inizializzare un jsonobject poiché in .NET per WinRT il costruttore Jsonobject () non prende alcun argomento.Per la memoria avrei potuto reso così nel quadro "regolare" .NET:

JsonObject root = new JsonObject(responseText);
.

Quello che ho perso?

È stato utile?

Soluzione

Se si desidera serializzare la risposta come JsonObject Dovresti utilizzare i metodi JsonObject.Parse(string) o JsonObject.TryParse(string, out JsonObject).

Altri suggerimenti

A meno che tu non abbia veramente bisogno di analizzare / attraversare una stringa codificata JSON, forse tutto ciò che devi è deseerializzarlo.Ecco Microsoft Docs per farlo.

Deserialize JSON codificato String

Ho personalmente come lavorare con l'API JSON di Newtonsoft per questa attività.

MyObject obj = JsonConvert.DeserializeObject<MyObject>(jsonEncodedString);
.

JSON API di NewtonSoft

Spero che questo aiuti.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top