public static EtcdResult Parse(string jsonStr) { Object obj; if (!SimpleJson.SimpleJson.TryDeserializeObject(jsonStr, out obj)) { return(null); } SimpleJson.JsonObject jsonObj = (SimpleJson.JsonObject)obj; EtcdResult result = new EtcdResult(); if (jsonObj.ContainsKey("errorCode")) { result.action = "unknown"; result.error = EtcdError.Parse(jsonObj); } else { if (jsonObj.ContainsKey("action")) { result.action = (string)jsonObj["action"]; } if (jsonObj.ContainsKey("node")) { result.node = EtcdResultNode.Parse((SimpleJson.JsonObject)jsonObj["node"]); } if (jsonObj.ContainsKey("prevNode")) { result.prevNode = EtcdResultNode.Parse((SimpleJson.JsonObject)jsonObj["prevNode"]); } } return(result); }
public static EtcdResultNode Parse(SimpleJson.JsonObject jsonObj) { EtcdResultNode node = new EtcdResultNode(); node.key = (string)jsonObj["key"]; node.createdIndex = (long)jsonObj["createdIndex"]; node.modifiedIndex = (long)jsonObj["modifiedIndex"]; if (jsonObj.ContainsKey("dir")) { node.dir = (bool)jsonObj["dir"]; } if (jsonObj.ContainsKey("ttl")) { node.ttl = (long)jsonObj["ttl"]; } if (jsonObj.ContainsKey("expiration")) { DateTime expiration; if (DateTime.TryParse((string)jsonObj["expiration"], out expiration)) { node.expiration = expiration; } } if (jsonObj.ContainsKey("value")) { node.value = (string)jsonObj["value"]; } if (jsonObj.ContainsKey("nodes")) { SimpleJson.JsonArray children = (SimpleJson.JsonArray)jsonObj["nodes"]; node.nodes = new EtcdResultNode[children.Count]; for (int i = 0; i < children.Count; ++i) { node.nodes[i] = Parse((SimpleJson.JsonObject)children[i]); } } return(node); }