Exemplo n.º 1
0
 public string[] GetStringArrayValue(string name)
 {
     if (values != null)
     {
         IJsonValue ij;
         if (values.TryGetValue(name, out ij))
         {
             JsonDataArray a = ij as JsonDataArray;
             if (a != null)
             {
                 return(a.ToStringArray());
             }
         }
     }
     return(new string[] { });
 }
Exemplo n.º 2
0
 private static IJsonObject createJsonObject(object v, IJsonObject parent)
 {
     if (v == null)
     {
         return(null);
     }
     else
     {
         object[] vs = v as object[];
         if (vs != null)
         {
             JsonDataArray ja = new JsonDataArray(parent);
             for (int i = 0; i < vs.Length; i++)
             {
                 ja.Add(createJsonValue(vs[i], ja));
             }
             return(ja);
         }
         else
         {
             Dictionary <string, object> dc = v as Dictionary <string, object>;
             if (dc != null)
             {
                 JsonDataPropertyBag jp = new JsonDataPropertyBag(parent);
                 foreach (KeyValuePair <string, object> kv in dc)
                 {
                     jp.Add(kv.Key, createJsonValue(kv.Value, jp));
                 }
                 return(jp);
             }
             else
             {
                 throw new ArgumentException(string.Format("Unsupported object: [{0}]. Value:[{1}]", v.GetType().FullName, v));
             }
         }
     }
 }
Exemplo n.º 3
0
 public void FromJsonText(string jsonText)
 {
     Calls = new RequestCommand[] { };
     Data  = null;
     if (!string.IsNullOrEmpty(jsonText))
     {
         JavaScriptSerializer js = new JavaScriptSerializer();
         IJsonObject          jo = Json.StringToJson(jsonText);
         if (jo != null)
         {
             JsonDataPropertyBag prb = jo as JsonDataPropertyBag;
             if (prb != null)
             {
                 IJsonValue jv;
                 if (prb.TryGetValue("Calls", out jv))
                 {
                     JsonDataArray callsX = jv as JsonDataArray;
                     if (callsX != null)
                     {
                         if (callsX.Count > 0)
                         {
                             Calls = new RequestCommand[callsX.Count];
                             for (int i = 0; i < callsX.Count; i++)
                             {
                                 Calls[i] = new RequestCommand();
                                 JsonDataPropertyBag pb = callsX[i] as JsonDataPropertyBag;
                                 if (pb != null)
                                 {
                                     if (pb.TryGetValue("method", out jv))
                                     {
                                         JsonDataString sv = jv as JsonDataString;
                                         if (sv != null)
                                         {
                                             Calls[i].method = sv.ValueString;
                                         }
                                     }
                                     if (pb.TryGetValue("value", out jv))
                                     {
                                         JsonDataString sv = jv as JsonDataString;
                                         if (sv != null)
                                         {
                                             Calls[i].value = sv.ValueString;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 JsonDataArray clientData;
                 IJsonValue    jvalue;
                 if (prb.TryGetValue("values", out jvalue))
                 {
                     values = jvalue as JsonDataPropertyBag;
                 }
                 if (prb.TryGetValue("Data", out jvalue))
                 {
                     clientData = jvalue as JsonDataArray;
                     if (clientData != null)
                     {
                         Data        = new JsonDataSet();
                         Data.Tables = new JsonDataTable[clientData.Count];
                         for (int i = 0; i < clientData.Count; i++)
                         {
                             JsonDataTableUpdate tbl = new JsonDataTableUpdate();
                             Data.Tables[i] = tbl;
                             if (clientData[i] != null)
                             {
                                 JsonDataPropertyBag pb = clientData[i] as JsonDataPropertyBag;
                                 if (pb != null)
                                 {
                                     JsonDataArray rows;
                                     if (pb.TryGetValue("TableName", out jv))
                                     {
                                         JsonDataString name = jv as JsonDataString;
                                         Data.Tables[i].TableName = name.ValueString;
                                     }
                                     if (pb.TryGetValue("Columns", out jv))
                                     {
                                         JsonDataArray pbc = jv as JsonDataArray;
                                         if (pbc != null && pbc.Count > 0)
                                         {
                                             Data.Tables[i].Columns = new JsonDataColumn[pbc.Count];
                                             for (int c = 0; c < pbc.Count; c++)
                                             {
                                                 Data.Tables[i].Columns[c] = new JsonDataColumn();
                                                 JsonDataPropertyBag jsc = pbc[c] as JsonDataPropertyBag;
                                                 if (jsc != null)
                                                 {
                                                     if (jsc.TryGetValue("Name", out jv))
                                                     {
                                                         JsonDataString jds = jv as JsonDataString;
                                                         if (jds != null)
                                                         {
                                                             Data.Tables[i].Columns[c].Name = jds.ValueString;
                                                         }
                                                     }
                                                     if (jsc.TryGetValue("ReadOnly", out jv))
                                                     {
                                                         JsonDataBool jdb = jv as JsonDataBool;
                                                         if (jdb != null)
                                                         {
                                                             Data.Tables[i].Columns[c].ReadOnly = jdb.ValueBool;
                                                         }
                                                     }
                                                     if (jsc.TryGetValue("Type", out jv))
                                                     {
                                                         JsonDataString jds = jv as JsonDataString;
                                                         if (jds != null)
                                                         {
                                                             Data.Tables[i].Columns[c].Type = jds.ValueString;
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                     if (pb.TryGetValue("PrimaryKey", out jv))
                                     {
                                         JsonDataArray pbc = jv as JsonDataArray;
                                         if (pbc != null && pbc.Count > 0)
                                         {
                                             Data.Tables[i].PrimaryKey = new string[pbc.Count];
                                             for (int c = 0; c < pbc.Count; c++)
                                             {
                                                 Data.Tables[i].PrimaryKey[c] = pbc[c].ToString();
                                             }
                                         }
                                     }
                                     if (pb.TryGetValue("rowIndex", out jv))
                                     {
                                         JsonDataNumber jn = jv as JsonDataNumber;
                                         if (jn != null)
                                         {
                                             tbl.RowIndex = jn.ValueNumber;
                                         }
                                     }
                                     if (pb.TryGetValue("Rows", out jv))
                                     {
                                         rows = jv as JsonDataArray;
                                         if (rows != null)
                                         {
                                             Data.Tables[i].Rows = new JsonDataRow[rows.Count];
                                             for (int m = 0; m < rows.Count; m++)
                                             {
                                                 JsonDataPropertyBag r = rows[m] as JsonDataPropertyBag;
                                                 if (r != null)
                                                 {
                                                     JsonDataRowUpdate jdr = new JsonDataRowUpdate();
                                                     Data.Tables[i].Rows[m] = jdr;
                                                     if (r.TryGetValue("KeyValues", out jv))
                                                     {
                                                         JsonDataArray keys = jv as JsonDataArray;
                                                         if (keys != null)
                                                         {
                                                             jdr.KeyValues = new object[keys.Count];
                                                             for (int k = 0; k < keys.Count; k++)
                                                             {
                                                                 if (keys[k] != null)
                                                                 {
                                                                     JsonDataValue jdv = keys[k] as JsonDataValue;
                                                                     if (jdv != null)
                                                                     {
                                                                         jdr.KeyValues[k] = jdv.Value;
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                     if (r.TryGetValue("added", out jv))
                                                     {
                                                         if (((JsonDataBool)jv).ValueBool)
                                                         {
                                                             jdr.Added = true;
                                                         }
                                                     }
                                                     if (r.TryGetValue("deleted", out jv))
                                                     {
                                                         if (((JsonDataBool)jv).ValueBool)
                                                         {
                                                             jdr.Deleted = true;
                                                         }
                                                     }
                                                     if (r.TryGetValue("ItemArray", out jv))
                                                     {
                                                         JsonDataArray rowsData = jv as JsonDataArray;
                                                         if (rowsData != null)
                                                         {
                                                             Data.Tables[i].Rows[m].ItemArray = new object[rowsData.Count];
                                                             if (rowsData.Count > 0)
                                                             {
                                                                 for (int c = 0; c < rowsData.Count; c++)
                                                                 {
                                                                     if (rowsData[c] != null)
                                                                     {
                                                                         JsonDataValue jv0 = rowsData[c] as JsonDataValue;
                                                                         if (jv0 != null)
                                                                         {
                                                                             Data.Tables[i].Rows[m].ItemArray[c] = jv0.Value;
                                                                         }
                                                                         else
                                                                         {
                                                                             JsonDataArray jva = rowsData[c] as JsonDataArray;
                                                                             if (jva != null)
                                                                             {
                                                                                 Data.Tables[i].Rows[m].ItemArray[c] = jva.ToByteArray();
                                                                             }
                                                                         }
                                                                     }
                                                                 }
                                                             }
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 OnParseJsonText(prb);
             }
         }
     }
 }