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 EtcdError Parse(SimpleJson.JsonObject jsonObj) { EtcdError error = new EtcdError(); error.errorCode = (long)jsonObj["errorCode"]; error.index = (long)jsonObj["index"]; if (jsonObj.ContainsKey("cause")) { error.cause = (string)jsonObj["cause"]; } error.message = (string)jsonObj["message"]; return(error); }