【问题标题】:Pass JSON parameter to Web API将 JSON 参数传递给 Web API
【发布时间】:2015-08-08 11:50:13
【问题描述】:

我希望你能再次帮助我,我有一个包含对象容器的 c# 类,我需要从 json 对象填充这个类对象。

public class user { public string name {get;set;} public userAttributes {get;set;}}

public class userAttributes { int id {get; set;} string value {get;set;}}

我正在使用 google postman 使用 url 编码选项来传递参数,但我不知道能够获取此参数的确切 json 格式是什么。我正在像这样传递 userAttribute:

"userAttributes": [
{
  "Values": [
    {
      "id": 1,
      "Value": "sample string 2"
    },
    {
      "id": 1,
      "Value": "sample string 2"
    }
  ]

【问题讨论】:

  • Serialize userAttributes 类型的对象,你有它。

标签: c# .net json asp.net-web-api


【解决方案1】:

你可以试试这个,

public class UserAttribute
{
    public string Id { get; set; }
    public string Value { get; set; }
}       
public class UserAttributes
{
    public IList<UserAttribute> UserAttributes { get; set; }
}

json

 {"UserAttributes": [{  "Id":"1" , "Value":"sample string 1" }, 
                     {  "Id":"2" , "Value":"sample string 2" }]}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 2019-05-14
    • 1970-01-01
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多