Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
	  }
  }]
}
}


What I have tried:

I have googled, no joy, moved the braces and the square bracket, no joy.
Posted
Updated 4-Apr-19 1:57am
Comments
Richard Deeming 4-Apr-19 7:52am    
We can't answer that - we have no idea what the API you're posting to is expecting.

As a pure guess, the nested line object looks a little suspicious to me. I'd expect it to look more like:
"lines":[{
    "product": "ABS123",
    "extendeddescription": "Product description",
    "quantity": 1,
    "price": 100
}]


But without knowing what the API expects, that's just a guess.
MKM_Matt 4-Apr-19 8:07am    
Thanks Richard, yes you don't know the API I am putting it against, but appreciate the comment about the line looking suspicious, have changed so same as yours. I will go back to the providers and check the tags with them, (am thinking incorrect name now), but they are ridiculously slow at replying. Thanks again.

1 solution

Check the data against your classes. A quick run through of that via json2csharp - generate c# classes from json[^]
gives:
C#
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; }
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900