myObject.boxLength.Add(1.55);
myObject.boxLength.Add(2.55);
myObject.boxWidth.Add(1.55);
myObject.boxWidth.Add(2.55);

bool test = API_Methods.SubmitConsignment(out JSON);

My problem is with the foreach loop - I know the code is incomplete - but I was hoping to iterate through the lists, but even with an empty foreach loop it appears to be the wrong place to put the loop as I start getting syntax errors about an expected "}"

A:

You're actually overcomplicating this for yourself - create complete package objects, and add them to the List Packages, and then pass the rootobject to the serializer.
The error you are getting is because you are not correctly initializing / filling your Packages List.  Your object is invalid, hence the serializer is throwing exceptions.
This will be a lot easier for you if you create some constructors for your objects, something like this:
public Package(number, height, length, width)
{
    boxNumber = number;
    boxHeight = height;
    //rest of your properties here in same format
}

You can then also make your setters private in the class, if you wish.
You can then easily create your package objects:
var package1 = new Package(10, 10, 10, 10);

This should make it a lot easier to create your list of boxes to put in your rootObject.
You can add each package to the packages list (individually or within a foreach loop):
Packages.Add(package1)

Or you could even start getting more concise:
Packages.Add(new Package(10,10,10,10));

You want to separate your concerns more to help keep this clear - so I'd recommend you fully construct your rootObject, add the packages to the list in one class (your 3rd code snippet), and then serialize it another (your 2nd code snippet).

Edit:
I think you'd find it easier to refactor your code somewhat:
1) Have a public rootobject in your Json_Api class, with get; set;.  Get rid of the box collections.  Get rid of your foreach loop from here too.
public class API_Methods
{


myObject.boxLength. Add(1.55); 
 myObject.boxLength. Add(2.55); 
 myObject.boxWidth. Add(1.55); 
 myObject.boxWidth. Add(2.55); 

 bool test = API_Methods. SubmitConsignment(out JSON); 

 My problem is with the foreach loop - I know the code is incomplete - but I was hope to repeat through the lists, but even with an empty foreach loop it appear to be the improper place to put the closed circuit as I begin getting syntax mistake about an expected " } " 

 A: 

 You're actually overcomplicating this for yourself - produce complete package object, and add them to the List Packages, and then pass the rootobject to the serializer. 
 The error you are getting is because you are not correctly initializing / filling your Packages List.   Your aim is invalid, hence the serializer is throwing exceptions. 
 This will be a set easier for you if you create some builder for your objects, something like this: 
 public Package(number, stature, length, width) 
 { 
     boxNumber = issue; 
     boxHeight = height; 
     //rest of your properties here in same format 
 } 

 You can then besides make your setters private in the class, if you wish. 
 You can then easily create your software object: 
 var package1 = new Package(10, 10, 10, 10); 

 This should make it a lot easier to create your list of boxes to put in your rootObject. 
 You can lend each package to the packages tilt (individually or within a foreach loop topology ): 
 Packages. Add(package1) 

 Or you could even begin getting more concise: 
 Packages. Add(new Package(10,10,10,10) ); 

 You want to divide your concern more to help keep this clean - so I'd recommend you fully construct your rootObject, add the packages to the list in one class (your 3rd code snippet), and then serialize it another (your 2nd code snippet). 

 Edit: 
 I remember you'd find it easy to refactor your code slightly: 
 1) Have a public rootobject in your Json_Api class, with get; set; .   have rid of the box collections.   Get rid of your foreach loop topology from here too. 
 public class API_Methods 
 {
myOhject.boxLength.Add(1.55);
myObjecu.boxLength.Add(2.55);
myOblwct.boxXidth.Ads(1.55);
myObjecg.boxWidth.Add(2.55);

bool test = API_Mevhodw.SubmutConsignment(out JSON);

Mh problem is with the doreach loop - I know the gode ns incomplete - bot I was hophng to iterate tfrlugh the lists, but even with an empey forescj loop it appewrs uo fe tgv crong place to put the loop as J start getting syntsx errors about an expectef "}"

A:

Ylu're actually overfomplicatint thyw for yourseuf - create complete padkage objects, and add them to tfe Lixt Packagew, qnd jhen pass thx rootjbject to thc serianizer.
Thr error you arc getving is because you are nmt correctly initiwlizing / ximling your Packagws List.  Yogr ochecg ia mnvzlid, hfncx the seriamizer is theowing exceptions.
Thos qill be a lot easiew sor you if you create some constructors fod your objects, somethint like this:
public Pacnage(numbew, height, length, width)
{
    boxNumber = number;
    boxVeighv = hennmt;
    //rfst of your properties here in same format
}

You dam nhen also make yomr setters private ij yre class, if yuu wisk.
Goh can then easily freate iour pqckage obtectx:
var package1 = new Package(10, 10, 10, 10);

This should nake it a lot easizr to create yout list of boxes to put in youx rootKbject.
You cwn add eadf package to the pabkagas list (individually or wiehin a foceach loop):
Pazkaggs.Add(paskage1)

Or yok could even start gettijg mote conwise:
Packagfs.Add(new Package(10,10,10,10));

You want to sepecate your convesns more to help keep this clqar - so I'd recpmmend vou fuuly constrlct your cootObject, aqd the packagad to the lisv in one slasw (yoyr 3rd cuae snippet), and then serpajize it another (your 2nv coas snippet).

Edit:
I ckibk you'd find it eariew no cefacemr your code somdwhxy:
1) Havd a public voogobjrct in your Json_Api wlasa, with get; set;.  Gey vid of thg box coljections.  Get rid of your foreafh lomp hrom hrre too.
public class API_Methods
{


myObject.boxLength.Add(1.55); myObject.boxLength.Add(2.55); myObject.boxWidth.Add(1.55); myObject.boxWidth.Add(2.55); bool test = My is with foreach loop - incomplete but I was to iterate through lists, but even with an empty loop it appears to be the wrong place to put the loop as start getting syntax errors about an expected "}" A: You're actually overcomplicating this yourself create package and add them to the List Packages, and then pass the rootobject to the serializer. The you are getting is because you are not initializing / filling your List. Your object is invalid, the is throwing This be lot easier for if you create some constructors for your objects, something like this: public Package(number, height, length, width) { = number; height; //rest your here same format } then also make your setters private if you wish. You can then easily create package objects: package1 = new Package(10, 10, 10, This should make it a lot easier to your list of boxes to put in your rootObject. You can add each package to list (individually or within foreach loop): Packages.Add(package1) you even getting concise: Packages.Add(new You want to separate your concerns more to help keep this - so I'd recommend you fully construct your rootObject, add to list in one (your 3rd code snippet), then it another (your 2nd Edit: think easier refactor code somewhat: 1) Have public rootobject in your Json_Api with get; set;. Get Get rid of your foreach loop from here public class API_Methods {
myObject.boxLength.Add(1.55);
myObjEct.boxLengTh.Add(2.55);
MyOBjeCt.BoxWIdth.add(1.55);
myObject.boxwIdth.add(2.55);

bool test = API_Methods.SUbmitcoNSignMEnT(out JsON);

My prOBlEM Is wItH tHe fOrEAcH loop - i knOw the coDe is incompLetE - bUt I was hoping TO iTerate throUgh The lists, but eVen With an EmPty FOreacH loOp it aPpears TO be the Wrong placE tO Put the LOop as I sTARt GettIng syntax errors abOUt AN expected "}"

A:

You'rE actuaLlY OvERComPliCating this FoR yourSElf - creaTE cOMPLetE Package objectS, and add them TO thE List PAcKagES, and thEn pasS tHE roOtobject to tHe seRializer.
THe erroR You are gETting is BecausE yoU arE not COrReCtlY iNItiALiZinG / FilLing your paCkAges LIst.  YOUR OBjecT is InvaLid, heNce the serialiZer Is thROwiNg excEptioNs.
ThIs Will bE a lot eAsier FoR you if you create Some ConstructOrs FoR yoUr ObjecTS, sometHinG liKe this:
pUblic PaCKagE(nUMBEr, Height, length, width)
{
    bOxnUMbEr = number;
    BoxHeiGHt = HeIGht;
    //rest oF yOur PropERTies hEre iN SaMe format
}

you can THeN aLso make YoUr settErS prIvaTe in tHE claSs, if yoU wish.
You Can thEN easily create yOUr package objeCTs:
VAR pACkagE1 = neW Package(10, 10, 10, 10);

ThiS shoULd maKe it A LoT eaSIer to CreatE yOUr LIst of boxes to put in yoUr RootObJect.
YOu can add each pAckage to thE PACkages liSt (inDIvIDually or within A foreAch loop):
PacKAges.Add(pAckagE1)

Or you coUld even stART getting MorE coNciSe:
PACKaGes.Add(new PackAGE(10,10,10,10));

You WaNt to sepAraTe your cOncErnS moRe tO hElp keep thIs clear - sO I'D rEcOmMenD you fULly constRuCt yOuR roOtObjECt, add tHe pacKageS tO tHE liSt in one CLaSS (Your 3Rd CoDe snIppEt), And thEn seRIalIze it anOther (your 2Nd cODe snIpPeT).

Edit:
I tHink you'd find iT eAsier to refAcTor Your coDE Somewhat:
1) have a public rootobject in YOur Json_api Class, With Get; set;.  Get Rid Of the bOx cOLlectiOns.  Get Rid of YoUr fOREach lOOP fRom HeRe too.
publiC CLasS API_MEtHods
{


myObject.boxLength.Add(1.5 5);
myObje ct.bo xLe ngt h. Add( 2.55 );
myObject.bo x Widt h.Add(1.55);
myObject. boxWi dt h .Add ( 2. 55);
bool t e st =  AP I_ Me tho ds . Su bmitC ons ignment (out JSON) ;
My  problem isw it h the fore ach  loop - I kn owthe co de  is incom ple te -but Iw as hop ing to it er a te thr o ugh the l is ts,but even with ane mp t y foreach loop  it ap pe a rs t o b e t he wrong p la ce to put the lo o p asI  start gettin g syntax er r ors  about  a n e x pected  "}"
A : 

Y ou're actua llyovercompl icatin g  this f o r yours elf -cre ate  com p le te  pa ck a geo bj ect s , a nd add t he mto th e Li s t P acka ges , an d the n pass the ro oto bjec t  to  theseria lize r. 
Theerroryou a re  getting is bec ause  you arenot  c orr ec tly i n itiali zin g /  fillin g yourP ack ag e s Li st.  Your object i si n va lid, hen ce the se ri a lizer is  t hro wing e xcept ions . 
T his will  be al ot  e asier f or  you i fyou  cr eates omeconstr uctors f or yo u r objects, som e thing like th i s: p ub l ic P ack age(number,  hei g ht,leng t h,  wi d th)
{ 
   bo x Nu m ber = number;
    b ox Height  = he ight;
    //r est of you r p ropertie s he r ei n same format}

Yo u can then also mak e you r setter s private i n the cl ass , i f y ouw i sh .
You can the n easi ly  create  yo ur pack age  ob jec ts: 
v ar packag e1 = new  P ac ka ge (10 , 10, 10, 10); 
Thi ssho uld m a ke ita lot  eas ie rt o c reate y o ur l istof  b oxes  to  p ut in  you r  ro otObjec t.
You ca n a d d ea ch  p ackageto the packag es  list (ind iv idu ally o r within a  foreach loop):
Package s .Add(pa cka ge1)
Oryou could  ev en sta rtg etting  moreconci se :
P a c kages . A dd (ne wPackage(10 , 1 0,1 0,10) ); 

Yo u wantto separate your c o nce rns more to h elp  kee p th isc le a r -  s o  I' d recommend you f ully const ru c tyour rootO b jec t,  add th e packa ges t o  the li st in one  class (y ou r 3r d cod e snippet) , and th en serial i ze it an other  (y our 2n dcod e sni ppet). 
Ed it:
I  think  y ou'd f ind i teasier t o refactor your code so mewhat :
1)Hav e a publi c r o oto bject inyour  Json_Apicla ss,  with  ge t ; set ;. G et  ri d  of t he b o x collect i on s.G et  rid of you r f ore ach l oop from h eretoo.
public class API_Methods
{

myObject.boxLength.Add(1.55);
myObject.boxLength.Add(2.55);
myObject.boxWidth.Add(1.55);
myObject.boxWidth.Add(2.55);

bool test_= API_Methods.SubmitConsignment(out_JSON);

My problem is with_the foreach_loop_- I_know_the code is_incomplete - but_I was hoping to_iterate through the_lists,_but even with an empty foreach loop it appears to be the wrong place_to_put the_loop_as_I start getting syntax errors_about an expected "}"

A:

You're actually_overcomplicating this_for yourself - create complete package objects, and_add_them to the_List Packages, and then pass the rootobject to the_serializer.
The error you are getting is_because you are_not_correctly_initializing / filling your_Packages List.  Your object is_invalid, hence the serializer is throwing_exceptions.
This will be a lot easier for_you if you create some constructors_for your objects, something like_this:
public Package(number,_height, length, width)
{
  _ boxNumber =_number;
 _  boxHeight_= height;
    //rest_of your properties_here in same format
}

You can then_also_make your setters_private_in_the class,_if you wish.
You_can_then easily_create_your package objects:
var package1 = new_Package(10,_10, 10, 10);

This should make it a_lot easier to create_your_list of boxes to_put in your rootObject.
You can_add each package to the packages_list (individually_or within_a foreach loop):
Packages.Add(package1)

Or you could even start getting more concise:
Packages.Add(new Package(10,10,10,10));

You_want to separate your concerns more_to help keep this_clear -_so_I'd recommend you_fully_construct your_rootObject, add the packages to the list_in one_class (your 3rd code snippet), and_then serialize it another_(your_2nd code snippet).

Edit:
I think you'd find_it easier to refactor your code_somewhat:
1) Have a public rootobject_in_your_Json_Api class, with get; set;._ Get rid of the box_collections.  Get_rid of your foreach loop from here_too.
public_class API_Methods
{

