Skip to content

Instantly share code, notes, and snippets.

@jessgusclark
Created October 20, 2015 20:00
Show Gist options
  • Save jessgusclark/f5a255f65ea2c831d995 to your computer and use it in GitHub Desktop.
Save jessgusclark/f5a255f65ea2c831d995 to your computer and use it in GitHub Desktop.
Convert Object to JSON
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using UNCWebcomm;
using System.Runtime.Serialization; //Add Reference to
namespace NewsClasses {
[DataContract]
public class Keyword {
[DataMember]
public int Id { get; set; }
[DataMember]
public string Title { get; set; }
[DataMember]
public string Slug { get; set; }
[DataMember]
public bool Active { get; set; }
}
}
Keyword LoadKeyword = new Keyword();
MemoryStream stream1 = new MemoryStream();
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Keyword));
ser.WriteObject(stream1, LoadKeyword);
stream1.Position = 0;
StreamReader sr = new StreamReader(stream1);
string Json = (sr.ReadToEnd();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment