具体JSON / Geckoboard /部件趋势线C#类 [英] C# class for specific JSON / Geckoboard / Trendline widget
问题描述
有关Geckoboard我想产生这样一个JSON:
For Geckoboard I want to generate a JSON like this:
{
"item": [
{
"value": "274057"
},
[
"38594",
"39957",
"35316",
"35913",
"36668",
"45660",
"41949"
]
]
}
我与前阵缺少的属性挣扎。
I am struggling with the missing property before the array.
如何必须在C#类模样序列化到?
How must the C# Class look like to serialize to that?
推荐答案
这些作品罚款动态语言,如JavaScript,但它不是那么容易做到同样的事情在C#。我可以在这里看到最好的 - 这整个JSON将映射到下面的类结构:
Those works fine for dynamic languages, like javaScript, but it is not so easy to do same thing in C#. The best i can see here - this whole JSON will map to following class structure:
public class RootItem
{
public IEnumerable<object> Item {get;set;}
}
public class ValueItem
{
public string Value {get;set;}
}
和基本接下来,您将需要自定义序列规则或(取决于你在哪里使用它)参数粘结剂,将借此JSON和手工填写 RootItem.Item
集合与任一集 ValueItem
或的IEnumerable&LT;字符串方式&gt;
And basically next you will need a custom serializer rules or parameter binder (depending where you are using it), that will take this JSON and manually fill RootItem.Item
collection with either collection of ValueItem
or IEnumerable<string>
.
这篇关于具体JSON / Geckoboard /部件趋势线C#类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!