Ich versuche, einige Daten von einer GET-Anfrage zu speichern. Ich benutze StartCoroutine zur Anfrage und ich benutze Lambda-Ausdruck zum Speichern der Daten.GET Anfrage nicht speichern Daten
My-Code ist dies:
Using UnityEngine;
using System.Collections;
public class Test : MonoBehaviour {
// Use this for initialization
public void Start() {
string url1 = "http://localhost/virtualTV/query/?risorsa=";
string ciao = "http://desktop-pqb3a65:8080/marmotta/resource/ef299b79-35f2-4942-a33b-7e4d7b7cbfb5";
url1 = url1 + ciao;
WWW www1 = new WWW(url1);
var main=new JSONObject(JSONObject.Type.OBJECT);
var final= new JSONObject(JSONObject.Type.OBJECT);;
StartCoroutine(firstParsing((value)=>{main = value;
final= main.Copy();
Debug.Log(main);
}));
Debug.Log(final);
}
public IEnumerator firstParsing(System.Action<JSONObject> callback)
{
string url2 = "http://localhost/virtualTV/FirstQuery/?risorsa=";
string ciao = "http://desktop-pqb3a65:8080/marmotta/resource/ef299b79-35f2-4942-a33b-7e4d7b7cbfb5";
url2 = url2 + ciao;
WWW www2 = new WWW(url2);
yield return www2;
string json = www2.text;
//Parsing del json con creazione di un array
var firstjson = new JSONObject(json);
var tempVideo = new JSONObject(JSONObject.Type.OBJECT);
var array2 = new JSONObject(JSONObject.Type.OBJECT);
tempVideo.AddField ("id", firstjson.GetField ("id"));
tempVideo.AddField ("type", firstjson.GetField ("type"));
tempVideo.AddField ("url", firstjson.GetField ("url"));
array2.Add (tempVideo);
yield return array2;
callback (array2);
Debug.Log ("First Run" + array2);
}
Wenn ich versuche, nach dem Befehl FINAL zu verwenden,
final=main.copy()
es leer ist. Kannst du mir helfen, den Wert in der Variablen final zu speichern? Danke allen.
Was ist die Ausgabe von 'Debug.Log (main);'? –
Es enthält die JSON, die ich im Finale speichern möchte, kann es nicht Variable in Variable Finale kopieren, wenn ich final in StartCoroutine print es enthält JSON, danach ist es leer – user3836982
Erhalten Sie irgendwelche Fehler? –