Serialize JSON : Not working

Have following code to serialize the JSON but not working -- PLEASE HELP

 

 

Code 

using Terrasoft.Common.Json;

var diagCodeJson = Get>("DiagCode");
var jsonArray = new List();

foreach (var item in diagCodeJson) {
   jsonArray.Add(Json.Serialize(item));
}
string jsonString = "[" + Json.Serialize(jsonArray) + "]";
Set("DiagCodeString", jsonString);

return true;

 

 

Parameter value got using inspect

 

 

    "DiagCode": [
     {
       "HCDSDate_Out": "2008-01-18",
       "HCDDDisplay_Out": "Postlaminectomy syndrome, not elsewhere classified",
       "HCDDCodea_Out": "M96.1",
       "HCDBAmount_Out": 7239,
       "HCDAAmount1_Out": 2000,
       "HCDAAmount_Out": 5239
     },
     {
       "HCDSDate_Out": "2008-01-18",
       "HCDDDisplay_Out": "Chronic pain syndrome",
       "HCDDCodea_Out": "G89.4",
       "HCDBAmount_Out": 7239,
       "HCDAAmount1_Out": 2000,
       "HCDAAmount_Out": 5239
     },
     {
       "HCDSDate_Out": "2008-01-18",
       "HCDDDisplay_Out": "Other specified dorsopathies, sacral and sacrococcygeal region",
       "HCDDCodea_Out": "M53.88",
       "HCDBAmount_Out": 7239,
       "HCDAAmount1_Out": 2000,
       "HCDAAmount_Out": 5239
     },
     {
       "HCDSDate_Out": "2008-01-18",
       "HCDDDisplay_Out": "Spondylosis without myelopathy or radiculopathy, lumbar region",
       "HCDDCodea_Out": "M47.816",
       "HCDBAmount_Out": 7239,
       "HCDAAmount1_Out": 2000,
       "HCDAAmount_Out": 5239
     }
   ],
   "DiagCodeString": "Terrasoft.Common.CompositeObjectList`1[Terrasoft.Common.CompositeObject]"

 

 

Like 0

Like

2 comments

If you need to serialize JSON object you can use JsonConvert.SerializeObject from Newtonsoft.Json namespace.

 

Here is the sample of the code:

 

var collectionofObjects = new []
{ 
	new {
		HCDSDate_Out = "2008-01-18",
		HCDDDisplay_Out = "Postlaminectomy syndrome, not elsewhere classified",
		HCDDCodea_Out = "M96.1",
		HCDAAmount1_Out = 2000,
		HCDAAmount_Out = 5239
	},
	new {
		HCDSDate_Out = "2008-01-18",
		HCDDDisplay_Out = "Chronic pain syndrome",
		HCDAAmount1_Out = 2000,
		HCDAAmount_Out = 5239
	},
	new {
		HCDSDate_Out = "2008-01-18",
		HCDDDisplay_Out = "Other specified dorsopathies, sacral and sacrococcygeal region",
		HCDBAmount_Out = 7239,
		HCDAAmount1_Out = 2000,
		HCDAAmount_Out = 5239
	},
	new {
		HCDSDate_Out = "2008-01-18",
		HCDDDisplay_Out = "Spondylosis without myelopathy or radiculopathy, lumbar region",
		HCDDCodea_Out = "M47.816",
		HCDBAmount_Out = 7239,
		HCDAAmount1_Out = 2000,
		HCDAAmount_Out = 5239
	}
};
string jsonString = JsonConvert.SerializeObject(collectionofObjects);
Set("DiagCodeString", jsonString);

Thanks -- Got it after some digging -- did not know how to set Newtonsoft.Json -- now it is done and it all working fine thanks

Show all comments