C#-解析来自Zoho Creator Rest API的响应内容结果
解析Zoho Creator Rest API返回时遇到问题。样本返回结果: {{“formname”:[“RestAPI”,“operation”:[“add”,“values”:{“Name”:“Gary”,“Basic”:“10000”,“嗜好”:[“Reading”,“Writing”],“DOB”:“12-Jun-1980”,“Address”:“USA”,“ID”:89597000010897007},“status”:“Success”}] 使用以下代码返回JObject以获取属性:C#-解析来自Zoho Creator Rest API的响应内容结果,c#,rest,api,zoho,C#,Rest,Api,Zoho,解析Zoho Creator Rest API返回时遇到问题。样本返回结果: {{“formname”:[“RestAPI”,“operation”:[“add”,“values”:{“Name”:“Gary”,“Basic”:“10000”,“嗜好”:[“Reading”,“Writing”],“DOB”:“12-Jun-1980”,“Address”:“USA”,“ID”:89597000010897007},“status”:“Success”}] 使用以下代码返回JObject以获取属性
/* send post request here */
HttpContent _content = null;
var response = this.client.PostAsync(this.PostUrl,_content).Result;
/* parse request response here - need to record all data from return response */
string responseString = response.Content.ReadAsStringAsync().Result;
JObject result = JObject.Parse(responseString);
由于某些原因,我无法访问“result”对象的任何属性。我尝试过使用索引和JToken方法,但没有人返回我的值。我建议尝试JsonConvert.DeserializeObject(导入newtonsoft.json包)在你的responseString中使用它。你需要创建一个c#类,该类与你正在接收的JSON的结构相匹配,以使DeserializeObject方法工作。如果你只想使用。(无论属性如何)从响应中获取信息,我建议尝试JSON.Decode(responseString)丑陋,但它有效-不幸的是,它只适用于特定的返回,可能有一种使用类似方法的动态解决方案:
/* parse request response here - need to record all data from return response */
string responseString = response.Content.ReadAsStringAsync().Result;
JObject result = JObject.Parse(responseString);
var _formname = result["formname"] as JArray;
var step1 = _formname[1];
string operation = step1["operation"][0].ToString();
var values = step1["operation"][1]["values"];
var status = step1["operation"][1]["status"].ToString();
我希望避免创建类对象,但这是我唯一没有尝试过的东西。Json.Decode使用的名称空间是什么?@broseidon