使用C#从结果解析JSON数据 - 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结果的另一种方法。

这是我想要的Json结果数据。
使用C#从结果解析JSON数据 - c#

我知道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");
}

使用C#创建网页弹出窗口 - c#

如何使用c#创建打开的网页作为弹出窗口,并且在关闭弹出窗口时需要运行一个函数。我的意图是在成功完成活动后创建Web登录/注销并运行功能 参考方案 好吧,您并没有付出太多,但是,如果我猜您的体系结构是ASP.NET,那么您应该在页面代码中的服务器上有事件可以处理该事件。如果您对自己的要求有所了解,我们可以为您提供更多帮助。仅出于完整性考虑,您应该知道您不能只在…

JSON PATH字段NULL检查表达式 - java

我有一个像bellow的json数组:{ "store": { "book": [ { "category": "reference", "author": "Nigel Rees", "title": "Sa…

json_encode的特定方式 - php

所以这是我的PHP<?php include 'connect.php'; $sql = "SELECT name from startup_schema"; $result = mysqli_query($mysqli, $sql) or die("Error in Selecting " …

使用C#在Linux服务器中检查文件是否已使用.Net Core更新 - c#

我正在做一个.Net Core应用程序,需要检查某些文件最近是否被替换过。基本上检查文件是否被较新版本替换(它可能是同一文件或具有相同的大小,但是由于某种原因被替换了)。我今天在2020年3月4日下午12:32将文件上传到服务器,然后尝试使用File.GetLastWriteTime,但它给了我2019年2月27日,这可能是文件最初创建时或将文件下载到PC时…

使用C#在asp.net中获取Bootstrap下拉复选框的选中项 - c#

我正在一个网站上工作,在该网站上我需要用复选框代表下拉列表中的许多项目。为此,我使用bootstrap下拉复选框列表为: <head id="Head1" runat="server"> <title></title> <!-- Include Twitter Bootstra…