【发布时间】:2014-02-13 06:17:36
【问题描述】:
我正在使用 Netonsoft.Json 和 ASP.Net Web API。
我必须生成一个json字符串,如下所示,
"view":
[
{"id": "MAIN_TOP_IMAGE_b",
"image":
{
"value": "Base64 encoding(image.jpg)",
"type": "jpg;base64",
"align": "right"
}
},
{"id": "MAIN_BARCODE_a",
"barcode":
{
"value": " 32455232453",
"type": "QRCODE",
"caption": "1432343fdoadkfe"
}
}
]
我已经创建了一个如下的类,
public class View
{
[JsonProperty("id")]
public string Id { get; set; }
public Object ElementData { get; set; }
}
public class Image
{
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("align")]
public string Align { get; set; }
[JsonProperty("bgcolor")]
public string BGColor { get; set; }
}
public class Text
{
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("color")]
public string Color { get; set; }
[JsonProperty("align")]
public string Align { get; set; }
}
public class Barcode
{
[JsonProperty("value")]
public string Value { get; set; }
[JsonProperty("type")]
public string Type { get; set; }
[JsonProperty("caption")]
public string Caption { get; set; }
}
而 ElementData 将具有对象之一(图像、条形码、文本) elementdata 属性名称应使用其类型。
有什么办法吗?
【问题讨论】: