【问题标题】:json to .net class generator for wcf servicejson 到 wcf 服务的 .net 类生成器
【发布时间】:2015-07-14 13:46:56
【问题描述】:

我有这样的 JIRA json 字符串:

[
{
    "self": "http://www.example.com/jira/rest/api/2/project/EX",
    "id": "10000",
    "key": "EX",
    "name": "Example",
    "avatarUrls": {
        "48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10000",
        "24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10000",
        "16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10000",
        "32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10000"
    },
    "projectCategory": {
        "self": "http://www.example.com/jira/rest/api/2/projectCategory/10000",
        "id": "10000",
        "name": "FIRST",
        "description": "First Project Category"
    }
},
{
    "self": "http://www.example.com/jira/rest/api/2/project/ABC",
    "id": "10001",
    "key": "ABC",
    "name": "Alphabetical",
    "avatarUrls": {
        "48x48": "http://www.example.com/jira/secure/projectavatar?size=large&pid=10001",
        "24x24": "http://www.example.com/jira/secure/projectavatar?size=small&pid=10001",
        "16x16": "http://www.example.com/jira/secure/projectavatar?size=xsmall&pid=10001",
        "32x32": "http://www.example.com/jira/secure/projectavatar?size=medium&pid=10001"
    },
    "projectCategory": {
        "self": "http://www.example.com/jira/rest/api/2/projectCategory/10000",
        "id": "10000",
        "name": "FIRST",
        "description": "First Project Category"
    }
}
]

使用此 (http://jsonutils.com/) 将其转换为 .Net 类。但是,我想在我的 WCF 服务中使用这个类。我需要添加数据联系人和数据成员吗?

我正在获取如下头像网址(这是我班级的几行代码):

 public class AvatarUrls
    {
    public string 48x48 { get; set; }
    public string 24x24 { get; set; }
    public string 16x16 { get; set; }
    public string 32x32 { get; set; }
   }

如果我将“属性属性”设置为数据成员。它显示我的结果为:

    [DataContract]
    public class AvatarUrls
    {
        [DataMember(Name="48x48")]
        public string 48x48 { get; set; }
        [DataMember(Name="24x24")]
        public string 24x24 { get; set; }
        [DataMember(Name="16x16")]
        public string 16x16 { get; set; }
        [DataMember(Name="32x32")]
        public string 32x32 { get; set; }
    }

我在这里遇到的错误是: 1.找不到类型或命名空间名称“x48”(缺少汇编引用) 2. 字符串 -> 期望的类、委托、枚举、接口或结构

只是想知道,我可以在我的 WCF 代码中这样使用吗?我有点困惑,如果它正确与否?怎么了?我错过了什么吗?请帮忙。

【问题讨论】:

    标签: c# .net json wcf jira


    【解决方案1】:

    48x48 等不是有效的标识符,请将它们更改为Icon_48x48 之类的名称,并以与您相同的方式使用 DataMember 属性。

    【讨论】:

    • 非常感谢。该错误现在已被删除。顺便问一下,这个头像 URL 是什么?为什么要使用它?我们不能忽略这一点吗?任何示例代码示例?
    • 头像是一个代表用户的小图标。如果您不关心用户图片,那么可以忽略这些。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-22
    • 2013-11-29
    • 1970-01-01
    • 2016-06-04
    • 1970-01-01
    相关资源
    最近更新 更多