【问题标题】:Filtering json records procured from a file using asp.net webapi使用asp.net webapi过滤从文件中获取的json记录
【发布时间】:2017-02-18 14:20:46
【问题描述】:

我正在通过我的 api 从 json 文件中读取值。如何根据 id 过滤记录?

请在下面找到代码。

[HttpGet]
        public HttpResponseMessage Get(int id)
        {
            var productsjson = File.ReadAllText(HostingEnvironment.MapPath(@"~/App_Data/products.json"));


            var response = this.Request.CreateResponse(HttpStatusCode.OK);
            response.Content = new StringContent(productsjson, Encoding.UTF8, "application/json");
            return response;

        }

【问题讨论】:

    标签: json asp.net-web-api asp.net-web-api2


    【解决方案1】:

    没有看到 json 的内容/结构很难回答。理想情况下,您应该使用 Newtonsoft 或类似的工具将 productsjson 字符串解析为 json 对象。从那里您可以过滤对象/数组的内容,然后再将其返回给客户端

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-06
      • 2016-10-14
      • 1970-01-01
      • 2020-04-30
      • 2017-05-27
      • 2012-10-18
      • 1970-01-01
      相关资源
      最近更新 更多