Author Topic: [RESOLVED]Json & List of UILabel  (Read 3620 times)

ilanb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
[RESOLVED]Json & List of UILabel
« on: July 17, 2014, 10:06:12 AM »
Hello,

I try to put json value into List of Uilabel... without success : here is simple code test not finished...
Anyone can point me to right direction, I tried with list, dictionary...

Sorry is not problem with NGUI for sure :-)

  1. JSONObject emptyObject = new JSONObject();
  2.                
  3.                 emptyObject.Add("ilan", 1500);
  4.                 emptyObject.Add("marc", 850);
  5.                 emptyObject.Add("philip", 700);
  6.                 emptyObject.Add("mat", 650);
  7.                 emptyObject.Add("paul", 550);
  8.                 emptyObject.Add("joe", 425);
  9.                 emptyObject.Add("nico", 400);
  10.                 emptyObject.Add("ju", 300);
  11.                 emptyObject.Add("arno", 250);
  12.                 emptyObject.Add("paul", 100);
  13.                
  14. foreach (KeyValuePair<string, JSONValue> pair in emptyObject)
  15.  {
  16.         Debug.Log("name : score -> " + pair.Key + " : " + pair.Value);
  17.  
  18.         foreach (UILabel namelist in lblNameList)
  19.        {
  20.            //namelist.text = pair.Key;
  21.         }
  22.  
  23.         foreach (UILabel pointlist in lblPointList)
  24.         {
  25.            //pointlist.text = pair.Value.Type.ToString();
  26.         }
  27.  
  28.                 }
  29.  
  30.                

Thanks
« Last Edit: July 17, 2014, 06:12:13 PM by ilanb »

ilanb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Json & List of UILabel
« Reply #1 on: July 17, 2014, 02:59:39 PM »
Tested this :

  1. foreach(var item1 in dict.Keys)
  2.                 {
  3.                         foreach (UILabel namelist in lblNameList)
  4.                         {
  5.                                 namelist.text = item1;
  6.                                 //Debug.Log(item1);
  7.                         }
  8.                 }
  9.  
  10.                 foreach(var item2 in dict.Values)
  11.                 {
  12.                         foreach (UILabel pointlist in lblPointList)
  13.                         {
  14.                                 pointlist.text = item2;
  15.                                 //Debug.Log(item2);
  16.                         }
  17.                 }

for all UIlabel key and value are same, how I can loop from key/value and push in list of label

thx


ilanb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Json & List of UILabel
« Reply #2 on: July 17, 2014, 04:19:30 PM »
Latest test : but I have an error

Quote
IndexOutOfRangeException: Array index is out of range.

  1.  
  2. public List<UILabel> lbl1;
  3. public List<UILabel> lbl2;
  4.  
  5.  
  6.                 JSONObject emptyObject = new JSONObject();
  7.  
  8.                
  9.                 emptyObject.Add("kesfsdy", 1233);
  10.                 emptyObject.Add("otherKey", 123);
  11.                 emptyObject.Add("ketryrty", 567);
  12.                 emptyObject.Add("kwxcey", 908);
  13.  
  14. foreach (KeyValuePair<string, JSONValue> pair in emptyObject) {
  15.  
  16.                         string[,] table = { { pair.Key, pair.Value.ToString() } };
  17.  
  18.                         for (int i = 0; i < lbl1.Count; i++)
  19.                         {
  20.                                 lbl1[i].text = table[i, 0];
  21.                                 lbl2[i].text = table[i, 1];
  22.                         }
  23.                 }
  24.  

ilanb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Json & List of UILabel
« Reply #3 on: July 17, 2014, 04:38:24 PM »
same error with this :

  1. string[][] table;
  2.  
  3.                 foreach (KeyValuePair<string, JSONValue> pair in emptyObject) {
  4.  
  5.                         table = new string[][] { new string[] { pair.Key, pair.Value.ToString() } };
  6.  
  7.                         for (int i = 0; i < lbl1.Count; i++)
  8.                         {
  9.                                 lbl1[i].text = table[i][0];
  10.                                 lbl2[i].text = table[i][1];
  11.                         }
  12.                 }

 :( :o ???

ilanb

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Json & List of UILabel
« Reply #4 on: July 17, 2014, 06:11:40 PM »
ok founded :

  1.                 JSONObject emptyObject = new JSONObject();
  2.  
  3.                 emptyObject.Add("kesfsdy", 1233);
  4.                 emptyObject.Add("otherKey", 123);
  5.                 emptyObject.Add("ketryrty", 567);
  6.                 emptyObject.Add("kwxcey", 908);
  7.  
  8.                 List<string> myList1 = new List<string>();
  9.                 List<string> myList2 = new List<string>();
  10.  
  11.                 foreach (KeyValuePair<string, JSONValue> pair in emptyObject) {
  12.                         myList1.Add(pair.Key);
  13.                         myList2.Add(pair.Value.ToString());
  14.                 }
  15.  
  16.                 for (int i = 0; i < lbl1.Count; i++)
  17.                 {
  18.                         lbl1[i].text = myList1[i];
  19.                         lbl2[i].text = myList2[i];
  20.                 }

Maybe is not optimized... but works  :P