2

I have a key-value pair database table and need to convert it to a JSON stream programmaticlally using C#.

My table structure:

Table1
__________
Category
Title
Type
StageNumber
LineNumber
Key
Value

So I am going to need all of the fields: Category, Title, Type, StageNumber, LineNumber, and then the Key and Value in my stream.

I have created a class:

public class MyRecord
{

    public string Title { get; set; }
    public string Type { get; set; }
    public string Category { get; set; }
    public int StageNumber { get; set; }
    public int LineNumber { get; set; }
    public string FieldKey { get; set; }
    public string FieldValue { get; set; }
}

I am new to JSON, so could someone please point me in the right direction on how to proceed?

EZI
  • 15,209
  • 2
  • 27
  • 33
Coding Duchess
  • 6,445
  • 20
  • 113
  • 209

2 Answers2

2

the simplest way is:

var obj = new MyRecord();
var json = new JavaScriptSerializer().Serialize(obj);

For what you need a stream?

burning_LEGION
  • 13,246
  • 8
  • 40
  • 52
-1

//Serialize var obj = new MyRecord(); var json = new JavaScriptSerializer().Serialize(obj);

//Deserialize var obj = new JavaScriptSerializer().Deserialize(obj);

SP007
  • 1,871
  • 1
  • 22
  • 31