当我尝试从响应中获取 Json 数据时,它不起作用。 我是 Json 新手,所以我不知道如何解决这个问题。
这是我的 atm 代码:
//process ajax and make API call to active campaign
[HttpPost]
public ActionResult ProcessPreferences(string categoryTag, string userEmailAddr)
{
string applyToTag = categoryTag;
string emailAddr = userEmailAddr;
/*
* Active Campign API Integration
*/
// By default, this sample code is designed to get the result from your ActiveCampaign installation and print out the result
var acs = new Acs("api_key_removed", "api_url_removed");
Dictionary<string, string> getParameters = new Dictionary<string, string>();
getParameters.Add("api_action", "contact_view_email");
getParameters.Add("api_output", "json");
getParameters.Add("email", emailAddr);
var response = acs.SendRequest("GET", getParameters);
var obj = System.Web.Helpers.Json.Decode(response);
return Content(obj.tags);
}
}
我在谷歌上找到的所有东西都不起作用。 我尝试了这个,但它不起作用:
var obj = System.Web.Helpers.Json.Decode(response);
return Content(obj.tags);
我正在处理活跃的事件,因此可能是获取 json 结果的不同方法,不确定。
我知道 api 调用正在工作,因为我可以将 Json 数据写入浏览器控制台。 return Content(response);
然后用jquery编写。
最佳答案
这个问题已经有了答案,但我觉得有点麻烦。
仅仅为了将响应返回到相同的状态(JSON)而将响应转换为对象是没有意义的。
您需要返回响应:
[HttpPost]
public ActionResult ProcessPreferences(string categoryTag, string userEmailAddr)
{
...
var response = acs.SendRequest("GET", getParameters);
return Content(response, "application/json");
}
关于c# - 使用 C# 解析结果中的 JSON 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44753924/