string GetBalanceFromJson(string info) { string result = ""; MyJson.JsonNode_Object json = MyJson.Parse(info) as MyJson.JsonNode_Object; if (json.ContainsKey("result")) { MyJson.JsonNode_Object json_result = json["result"] as MyJson.JsonNode_Object; MyJson.JsonNode_Array stack = json_result["stack"] as MyJson.JsonNode_Array; if (stack != null && stack.Count >= 2) { string balance = ZoroHelper.GetJsonValue(stack[0] as MyJson.JsonNode_Object); string decimals = ZoroHelper.GetJsonValue(stack[1] as MyJson.JsonNode_Object); Decimal value = Decimal.Parse(balance) / new Decimal(Math.Pow(10, int.Parse(decimals))); string fmt = "{0:N" + decimals + "}"; result = string.Format(fmt, value); } } else if (json.ContainsKey("error")) { MyJson.JsonNode_Object json_error_obj = json["error"] as MyJson.JsonNode_Object; result = json_error_obj.ToString(); } return(result); }
byte ParseDecimals(string info) { byte decimals = 0; MyJson.JsonNode_Object json = MyJson.Parse(info) as MyJson.JsonNode_Object; if (json.ContainsKey("result")) { MyJson.JsonNode_Object json_result = json["result"] as MyJson.JsonNode_Object; MyJson.JsonNode_Array json_stack = json_result["stack"] as MyJson.JsonNode_Array; if (json_stack != null && json_stack.Count >= 1) { string value = ZoroHelper.GetJsonValue(json_stack[0] as MyJson.JsonNode_Object); decimals = byte.Parse(value); } } return(decimals); }