简体   繁体   English

当我返回一个列表时得到字符串

[英]getting string like when I return a list

The result I am getting我得到的结果

falsef005fdc9-7781-4c75-9f54-0a05a7fc6e71bc3d0990-2f44-491f-a25a-3771772d6a61false2017-10-10T08:43:16.0831010019false falsef005fdc9-7781-4c75-9f54-0a05a7fc6e71bc3d0990-2f44-491f-a25a-3771772d6a61false2017-10-10T08:43:16.0831010019false

I am getting like the format as below when I use the postman.当我使用 postman 时,我得到如下格式。

  1. Question: How do I remove [] ?问题:如何删除[] I tried to remove ToList() but it didn't work.我试图删除ToList()但它没有用。
  2. Question: Why I am getting a string like result instead of json?问题:为什么我得到一个类似结果的字符串而不是 json?

在此处输入图像描述

controller method controller 方法

public IEnumerable<ClientModel> GetClients()
{
    var clients = ClientHelper.GetAllClients();
    var result = (from c in clients
                  select c).ToList(); 

    return Mapper.Map<IEnumerable<ClientModel>>(result);

}

Use this namespace使用这个命名空间

using System.Web.Script.Serialization;

and

var json_result = new JavaScriptSerializer().Serialize(result );

You must get json data in json_result您必须在 json_result 中获取 json 数据

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想返回清单 <DictionaryClass<string,string> &gt;从网络服务中获取IDictionary错误 - i want to return List<DictionaryClass<string,string>> from web service but getting error for IDictionary 我从返回函数中得到这样的值现在我想要像这样的字符串 - Im get the value like this from a return fuction now i want the string like 当我返回ObservableCollection时,为什么会出现此超时错误? - Why am I getting this timeout error when I return an ObservableCollection? 当我将来自 Kafka 的消息放入字符串列表时,Memory 泄漏 - Memory leak when I put message from Kafka to list of string 如何使我的索引操作返回过滤列表而不添加查询字符串参数? - How can I make my index action return a filtered list without adding a query string parameter? 我有一个 csv 文件,其内容如下所示。 我如何将其转换为 List 的集合<string>动态? - I have a csv file whose contents is like as the following. How I can convert it to collection of List<string> dynamically? 如何使用SQLReader返回列表<string> - How to use SQLReader to return List<string> 从列表中查找并返回匹配的字符串 - Find and return matched string from List 当我想获取来自身份的用户列表时,我的 dbContext 返回 null - My dbContext return null, when I want get list of user, which are from identity 我需要一个下拉列表来显示活动案例列表,但是当有多个返回时,我一直收到错误 - I need a drop down list to display a list of active cases, but I keep getting an error when there is more than one returned
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM