Ich schreibe Android App in Xamarin C#.Herunterladen von Informationen aus JSON (Xamarin C#)
Ich analysiere Informationen von JSON und zeige es dann in Feldern.
Ich benutze diesen Code:
string url2 = "http://papajohn.pp.ua/?mkapi=getProductsByCat&cat_id=74";
JsonValue json = await FetchAsync(url2);
private async Task<JsonValue> FetchAsync(string url)
{
// Create an HTTP web request using the URL:
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Method = "GET";
// Send the request to the server and wait for the response:
using (WebResponse response = await request.GetResponseAsync())
{
// Get a stream representation of the HTTP web response:
using (Stream stream = response.GetResponseStream())
{
// Use this stream to build a JSON document object:
JsonValue jsonDoc = await Task.Run(() => JsonObject.Load(stream));
//dynamic data = JObject.Parse(jsonDoc[15].ToString);
Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
// Return the JSON document:
return jsonDoc;
}
}
}
Aber ich habe ein Problem. Wenn ich die Aktivität aktiviere, bleibt sie für 2-3 Sekunden stehen und alle Infos erscheinen in den Feldern.
Kann ich diesen Daten-Download reibungslos machen. Erstes Feld, dann zweites usw.
Und wenn ich kann, wie?
Sie könnten Volley verwenden, z.B. http://www.androidhive.info/2014/09/android-json-parsing-using-volley/ –
Dies ist für Java. Ich benutze C# @AlLelopath –
Zeigen Sie, wie Sie 'FetchAsync' aufrufen und setzen Sie die Werte auf Ihrer Ansicht. –