Hello everyone, I have project which uses Json data, I try deserialize a Json data like this :
[{"231":{"id":"231","reference":"01111","name":"Pomme","content_title":"","content":"","pv_ttc":"16.35","picture_1":"\/tdc\/webroot\/upload\/images\/avatar.jpg","picture_2":"\/tdc\/webroot\/upload\/images\/aaa.jpg","picture_3":"","picture_4":"","picture_5":""}]
the part of json data with "picture" have 5 pictures, so When I declare my method, the parameter of Picture is a String tab see:
public class productClass
{
public string id {get;set;}
public string reference { get; set; }
public string name{get;set;}
public string[] url{get;set;}
public float Prix{get;set;}
public string descriptif { get; set; }
public List urlResult;
public productClass ( string _id , string _reference, string _name ,string _descriptif, float _Prix,string[] _url )
{
id = _id;
reference = _reference;
name = _name;
descriptif = _descriptif;
Prix = _Prix;
for (int i = 0; i < url.Length; i++)
{
url [i] = _url [i];
}
urlResult = new List ( );
}
I would like to get back _url tab, consequently I think that I Have deserialize twice.
I know for one but two, I'm lost.
see my one deserialize:
public IEnumerator loadPicture (int cat)
{
WWW www = new WWW ( urlImg );
yield return www;
Debug.Log (www.text);
string json = www.text.ToString ( );
productClass[] products = JsonReader.Deserialize ( json );
//Debug.Log ( products.ToString ( ) );
foreach ( productClass item in products )
{
if ( firstLoad || gm.catId == 0 )
{
//productClass productClass = new productClass ( );
urlTextures.Add ( item.url );
idImg.Add ( item.id );
}
else if ( !firstLoad )
{
// productClass productClass = new productClass ( );
urlTextures.Add ( item.url );
idImg.Add ( item.id );
}
}
foreach ( string urlTexture in urlTextures )
{
WWW wwwTexture = new WWW(urlTexture);
yield return wwwTexture;
if ( !string.IsNullOrEmpty ( urlTexture ) )
{
imgProduct.Add ( wwwTexture.texture );
loader++;
}
else
{
imgProduct.Add ( noTex );
loader++;
}
}
firstLoad = false;
isLoading = false;
}
Thanks for help. :)
↧