[chronojump] Uses System.Json to deserialize the server's response for the person.



commit 3b397e8ed1fb5d9ef2b3375555337ac23a899299
Author: Carles Pina i Estany <carles pina cat>
Date:   Fri Jun 2 14:57:22 2017 -0400

    Uses System.Json to deserialize the server's response for the person.

 src/json.cs |   43 +++++++++++++------------------------------
 1 files changed, 13 insertions(+), 30 deletions(-)
---
diff --git a/src/json.cs b/src/json.cs
index b0387a8..040553f 100644
--- a/src/json.cs
+++ b/src/json.cs
@@ -331,7 +331,7 @@ public class Json
                else {
                        //patheticPersonDeserialize("[[2, \"(playername)\", 82.0, \"253,20,150,13\", \"\"]]");
                        //patheticPersonDeserialize("[[2, \"(playername)\", 82.0, \"253,20,150,13\", 
\"jugadors/player.jpg\"]]");
-                       person = patheticPersonDeserialize(responseFromServer);
+                       person = personDeserialize(responseFromServer);
                }
 
                return person;
@@ -339,41 +339,24 @@ public class Json
        }
        public double LastPersonByRFIDWeight = 0;
        public string LastPersonByRFIDImageURL = "";
-       private Person patheticPersonDeserialize(string str)
+       private Person personDeserialize(string strPeople)
        {
-               LogB.Information("str:|" + str + "|");
-               
-               string id = str.Substring(2, str.IndexOf(',') -2);
-               LogB.Information("id:|" + id + "|");
-
-               str = str.Substring(str.IndexOf('"') +1);
-               LogB.Information("str:|" + str + "|");
-               
-               string player = str.Substring(0, str.IndexOf('"'));
-               LogB.Information("player:|" + player + "|");
-               
-               str = str.Substring(str.IndexOf(',') +2);
-               LogB.Information("str:|" + str + "|");
+               JsonValue jsonPeople = JsonValue.Parse(strPeople);
 
-               string weight = str.Substring(0, str.IndexOf(','));
-               LogB.Information("weight:|" + weight + "|");
-               
-       
-               LastPersonByRFIDWeight = Convert.ToDouble(Util.ChangeDecimalSeparator(weight));
-               str = str.Substring(str.IndexOf('"') +1);
-               LogB.Information("str:|" + str + "|");
-               
-               string rfid = str.Substring(0, str.IndexOf('"'));
-               LogB.Information("rfid:|" + rfid + "|");
+               // We receive a list of people but we are interested only on the first one (?)
+               JsonValue person = jsonPeople [0];
 
-               str = str.Substring(str.IndexOf('"') +4);
-               LogB.Information("str:|" + str + "|");
+               Int32 id = person [0];
+               string player = person [1];
+               double weight = person [2];
+               double height = person [3];
+               string rfid = person [4];
+               string image = person [5];
 
-               string image = str.Substring(0, str.LastIndexOf('"'));
-               LogB.Information("image:|" + image + "|");
+               LastPersonByRFIDWeight = weight;
                LastPersonByRFIDImageURL = image;
 
-               return new Person(Convert.ToInt32(id), player, rfid);
+               return new Person(id, player, rfid);
        }
 
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]