Create nested json with c#

前端 未结 4 2117
日久生厌
日久生厌 2021-02-09 14:56

I am able to create a flat serialized JSON string pretty easily with c#

My issue is I want to create a nested string like this below

[ { 
    title: \"Y         


        
4条回答
  •  半阙折子戏
    2021-02-09 15:20

    using System.Web.Script.Serialization;
     
    
    
    var strNJson = new
                {
                    to = "hello",
                    notification = new
                    {
                        title = "textTitle",
                        body = "bodyText"
                    }
                };
                JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                string json = javaScriptSerializer.Serialize(strNJson);
    
    {   "to":"hello",
           "notification": {
                            "title":"titleText",
                             "body":"bodyText"
                         } 
    }
    

提交回复
热议问题