Json Convert Serialize Object - CSharp System

CSharp examples for System:Converter

Description

Json Convert Serialize Object

Demo Code


using Newtonsoft.Json;

public class Main{
        public static string GetPartialIndexBulk(string index, string type, object id, object value, object parent = null)
        {//from  w  w  w  . j a  v a 2  s .c o m
            if (parent == null)
                return string.Format("{0}\n{1}\n",
                    JsonConvert.SerializeObject(new { index = new { _index = index, _type = type, _id = id } }, Formatting.None),
                    JsonConvert.SerializeObject(value, Formatting.None));
            else

                return string.Format("{0}\n{1}\n",
                    JsonConvert.SerializeObject(new { index = new { _index = index, _type = type, _id = id, parent = parent } }, Formatting.None),
                    JsonConvert.SerializeObject(value, Formatting.None));
        }
        public static string GetPartialIndexBulk(string index, string type, object value)
        {
            return string.Format("{0}\n{1}\n",
                JsonConvert.SerializeObject(new { index = new { _index = index, _type = type } }, Formatting.None),
                JsonConvert.SerializeObject(value, Formatting.None));
        }
}

Related Tutorials