示例#1
0
    IEnumerator Load()
    {
        string url = "http://158.69.197.37:8080/api/product/byAppliance?applianceID=" + id;
        WWW    www = new WWW(url);

        //Load the data and yield (wait) till it's ready before we continue executing the rest of this method.
        yield return(www);

        if (www.error == null)
        {
            //Sucessfully loaded the JSON string

            LoadJsonCategorias instance    = LoadJsonCategorias.instance;
            JsonData           jsonOfertas = JsonMapper.ToObject(www.text);
            List <Categoria>   cat         = new List <Categoria> ();

            if (jsonOfertas ["result"].Count == 0)
            {
                instance.CreateButton(null, cat, false, true, false);
            }
            else
            {
                for (int i = 0; i < jsonOfertas ["result"].Count; i++)
                {
                    auxC = instance.CreateButton(jsonOfertas ["result"] [i], cat, false, true, true);

                    nombre = auxC.transform.FindChild("TextName").GetComponent <Text> ().text;
                    //nombre = auxC.gameObject.GetComponentInChildren<Text> ().text;
                    //Environment.NewLine + ingresa un salto de linea
                    //auxC.gameObject.GetComponentInChildren<Text> ().text += "    " + "Precio 1: " + jsonOfertas ["result"] [i] ["price"] + "   ||   " + "Precio 2: " + jsonOfertas ["result"] [i] ["price2"]+ "   ||   " + "Precio 3: " + jsonOfertas ["result"] [i] ["price3"];

                    Image auxM = auxC.transform.FindChild("Image").GetComponent <Image> () as Image;
                    StartCoroutine(loadImage(jsonOfertas ["result"] [i] ["image"].ToString(), auxM));


                    descripcion = auxC.transform.FindChild("TextDesc").GetComponent <Text> ().text;
                    auxC.transform.FindChild("TextDesc").GetComponent <Text> ().text = jsonOfertas ["result"] [i] ["description"].ToString();


                    precio = auxC.transform.FindChild("TextPrice").GetComponent <Text> ().text;
                    auxC.transform.FindChild("TextPrice").GetComponent <Text> ().text += "Precio 1: " + jsonOfertas ["result"] [i] ["price"] + "   ||   " + "Precio 2: " + jsonOfertas ["result"] [i] ["price2"] + "   ||   " + "Precio 3: " + jsonOfertas ["result"] [i] ["price3"];
                }
            }
            subcategoria = cat.ToArray();
            LoadJsonCategorias.instance.cargando.SetActive(false);
        }
        else
        {
            Debug.Log("ERROR: " + www.error);
            LoadJsonCategorias.instance.error.SetActive(true);
        }
    }
示例#2
0
    IEnumerator Start()
    {
        instance = this;
        backButton.SetActive(false);
        error.SetActive(false);
        cargando.SetActive(true);
        //Load JSON data from a URL
        string url = "http://158.69.197.37:8080/api/appliances/categories";
        WWW    www = new WWW(url);

        //Load the data and yield (wait) till it's ready before we continue executing the rest of this method.
        yield return(www);

        if (www.error == null)
        {
            //Sucessfully loaded the JSON string
            ProcessCategorias(www.text);
        }
        else
        {
            Debug.Log("ERROR: " + www.error);
            error.SetActive(true);
        }
    }