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
  • 14,888
  • 2
  • 26
  • 32
Coding Duchess
  • 5,997
  • 13
  • 93
  • 182

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
  • 12,864
  • 8
  • 38
  • 50
-1

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

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

SP007
  • 1,821
  • 1
  • 21
  • 31