[英]Parse JSON data from result with C#
当我尝试从响应中获取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);
}
}
我在Google上找到的所有内容均无法正常运行。 我尝试了这个,但是没有用:
var obj = System.Web.Helpers.Json.Decode(response);
return Content(obj.tags);
我正在使用活动广告系列,因此可能不确定获取json结果的另一种方法。
我知道api调用正在运行,因为我可以将Json数据写入浏览器控制台。 return Content(response);
然后用jquery编写。
这个问题已经回答了,但是我认为这很麻烦。
将respnse转换为对象只是为了使其返回到相同状态(JSON),这没有意义。
您需要按原样返回响应:
[HttpPost]
public ActionResult ProcessPreferences(string categoryTag, string userEmailAddr)
{
...
var response = acs.SendRequest("GET", getParameters);
return Content(response, "application/json");
}
代替ActionResult,选择JsonResult。 试试下面的代码:
public JsonResult ActionName()
{
your code goes here ....
return Json(outputobj);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.