Click here to Skip to main content
15,914,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
{"ResCode":1,"ResStrDisplay":"{"EmpId":16,"FullName":"GTPTEST","Designation":"Software Engineer","LastActivity":"Sign in recorded at 02/12/2016 15:23 from IP address: 115.118.170.121"}"}
I have get this output.
I want following output.
{"ResCode":1,"ResStrDisplay":{"EmpId":16,"FullName":"GTPTEST","Designation":"Software Engineer","LastActivity":"Sign in recorded at 02/12/2016 15:23 from IP address: 115.118.170.121"}}

{"ResCode":1,"ResStrDisplay":"{...}"}i want to remove this " " marks.
I want to remove "{..}" this "" marks.before bracket and after bracket
this is my code


C#
WebEmployees ObjWebEmp = new WebEmployees();
                   ObjWebEmp.EmpId = objUser.UserId;
                   ObjWebEmp.FullName = objUser.FullName;
                   ObjWebEmp.Designation = objUser.Designation;
                   ObjWebEmp.LastActivity = lastactivity;
                   um.ResCode = 1;
                   um.ResStrDisplay = new JavaScriptSerializer().Serialize(ObjWebEmp);


What I have tried:

C#
WebEmployees ObjWebEmp = new WebEmployees();
                   ObjWebEmp.EmpId = objUser.UserId;
                   ObjWebEmp.FullName = objUser.FullName;
                   ObjWebEmp.Designation = objUser.Designation;
                   ObjWebEmp.LastActivity = lastactivity;
                   um.ResCode = 1;
                   um.ResStrDisplay = new JavaScriptSerializer().Serialize(ObjWebEmp);
Posted

1 solution

The fact that there is a quotation mark (") before the open bracket ("{") usually mean that the value is itself a json string, and this is infact exactly what you are doing. When you deserialize the string you should allow ResStrDisplay to be a string and then deserialize that into the object.

The issue is that a json serialization will include escape chars where needed so doing it twice will add further escape chars. if you try to deserialize by manipulating the string you will have to take that into account.

Another option (and the one I use) is to not pre-serialize ResStrDisplay. If you leave it as an object then the serialization of the whole WebEmployees object will produce the format you expect.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900