public string GetStringValue(string name) { if (values != null) { IJsonValue ij; if (values.TryGetValue(name, out ij)) { JsonDataString ds = ij as JsonDataString; if (ds != null) { return(ds.ValueString); } JsonDataValue dv = ij as JsonDataValue; if (dv != null) { if (dv.Value == null) { return(null); } return(dv.Value.ToString()); } } } return(null); }
public string[] ToStringArray() { string[] bs = new string[this.Count]; for (int i = 0; i < this.Count; i++) { JsonDataString jvn = this[i] as JsonDataString; if (jvn != null) { bs[i] = jvn.ValueString; } } return(bs); }
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); } } } }