JSON,创建订单,但不创建订单行。 [英] JSON, creating order, but not creating the order lines.

查看:87
本文介绍了JSON,创建订单,但不创建订单行。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JSON的新手,所以毫无疑问这对你们来说很容易;-)。

我可以发布以下内容并创建订单,但它不是添加任何行。有人可以查看代码,看看它是否结构正确,感谢你不知道应该写什么标签,但格式是否正确?



我还有那里的多行地址位吗?



这个订单只适用于一行,其他订单将是多行,但我不能甚至得到了一个单行的订单...感谢所有的帮助。



I am new to JSON, so no doubt this is an easy one for you experts ;-).
I am able to post the following and it is creating the order, but it is not adding any lines. Could someone please check out the code and see if it is structurally correct, appreciate you don't know what tags should be written to, but is the format correct?

Also do I have the address bits right for multiple lines in there?

This order is just for one line, other orders will be multiple lines, but I can't even get a one line order in... All assistance gratefully received.

{"header":
{
  "account": "0000420",
  "reference": "1234",
  "name": "Fred Jones",
  "address": {
    "line": ["Address line 1",
    "Address line 2",
    "Address line 3",
    "Address line 4"
    ],
    "postcode": "post"
  },
  "deliverycountry": "GB",
  "invoicename": "Fred Jones",
  "invoicecountry": "GB",
  "instructions": "Sample text inst",
  "ordertype": "sale",
  "lines": [{
	  "line": {
	    "product": "ABC123",
	    "extendeddescription": "Product description",
	    "quantity": 1,
	    "price": 100
	  }
  }]
}
}





我的尝试:



我用Google搜索,没有欢乐,移动括号和方括号,没有快乐。



What I have tried:

I have googled, no joy, moved the braces and the square bracket, no joy.

推荐答案

根据您的班级检查数据。通过 json2csharp快速浏览 - 从json生成c#类 [ ^ ]

给出:

Check the data against your classes. A quick run through of that via json2csharp - generate c# classes from json[^]
gives:
public class Address
{
    public List<string> line { get; set; }
    public string postcode { get; set; }
}

public class Line2
{
    public string product { get; set; }
    public string extendeddescription { get; set; }
    public int quantity { get; set; }
    public int price { get; set; }
}

public class Line
{
    public Line2 line { get; set; }
}

public class Header
{
    public string account { get; set; }
    public string reference { get; set; }
    public string name { get; set; }
    public Address address { get; set; }
    public string deliverycountry { get; set; }
    public string invoicename { get; set; }
    public string invoicecountry { get; set; }
    public string instructions { get; set; }
    public string ordertype { get; set; }
    public List<Line> lines { get; set; }
}

public class RootObject
{
    public Header header { get; set; }
}


这篇关于JSON,创建订单,但不创建订单行。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆