json 到 .net class wcf 服务生成器
json to .net class generator for wcf service
我有这样的 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 class。但是,我想在我的 WCF 服务中使用这个 class。我需要添加数据联系人和数据成员吗?
我正在获取如下头像 url(这是我 class 中的几行代码):
public class AvatarUrls
{
public string 48x48 { get; set; }
public string 24x24 { get; set; }
public string 16x16 { get; set; }
public string 32x32 { get; set; }
}
如果我将 "Property Attributes" 设置为数据成员。结果显示为:
[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.The 类型或名称空间名称 "x48"(缺少 assemble 引用)
2. 字符串 -> 预期 class、委托、枚举、接口或结构
只是想知道,我可以在我的 WCF 代码中这样使用吗?我有点困惑,它是否正确?怎么了?我错过了什么吗?请帮助。
48x48
等不是有效的标识符,请将它们更改为 Icon_48x48
之类的内容,并按照您已经使用的相同方式使用 DataMember 属性。
我有这样的 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 class。但是,我想在我的 WCF 服务中使用这个 class。我需要添加数据联系人和数据成员吗?
我正在获取如下头像 url(这是我 class 中的几行代码):
public class AvatarUrls
{
public string 48x48 { get; set; }
public string 24x24 { get; set; }
public string 16x16 { get; set; }
public string 32x32 { get; set; }
}
如果我将 "Property Attributes" 设置为数据成员。结果显示为:
[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.The 类型或名称空间名称 "x48"(缺少 assemble 引用) 2. 字符串 -> 预期 class、委托、枚举、接口或结构
只是想知道,我可以在我的 WCF 代码中这样使用吗?我有点困惑,它是否正确?怎么了?我错过了什么吗?请帮助。
48x48
等不是有效的标识符,请将它们更改为 Icon_48x48
之类的内容,并按照您已经使用的相同方式使用 DataMember 属性。