Dan:
You don't need to do anything like that when using JSON.
Take a look at the following code:
using System;
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
namespace jsontest
{
class bomitem
{
public int quantity;
public int partnumber;
public string catalognumber;
public string description;
}
class Program
{
static void Main(string[] args)
{
bomitem bom1 = new bomitem();
bomitem bom2 = new bomitem();
bomitem bom3 = new bomitem();
bom1.quantity = 4;
bom1.partnumber = 01;
bom1.catalognumber = "90I0200";
bom1.description = "Meter, Red Lion #CUB4V";
bom2.quantity = 9;
bom2.partnumber = 02;
bom2.catalognumber = "90X0199";
bom2.description = "Pilot Light, 24V DC, Green, SQ-D";
bom3.quantity = 100;
bom3.partnumber = 03;
bom3.catalognumber = "23M1234";
bom3.description = "Line Reactor, 5KW, MTE Corporation";
bomitem[] boms = new bomitem[] { bom1, bom2, bom3 };
string output = JavaScriptConvert.SerializeObject(boms);
Console.WriteLine(output);
Console.ReadLine();
}
}
}
It outputs:
[{"quantity":4,"partnumber":1,"catalognumber":"90I0200","description":"Meter, Red Lion #CUB4V"},{"quantity":9,"partnumber":2,"catalognumber":"90X0199","description":"Pilot Light, 24V DC, Green, SQ-D"},{"quantity":100,"partnumber":3,"catalognumber":"23M1234","description":"Line Reactor, 5KW, MTE Corporation"}]
Then when I deserialize it I can convert it back into an array of bomitems.