Hello... I am new to WCF but currently working on WCF Restful service. In my senario i need to get Json file in a serialized format. Here is my code sample.
I have two files inside app_code one is "sample.cs" and another one is "Isample.cs".
Inside sample.cs
public List<Contacts> GetContactListAsJson()
{
return GetContactList();
}
Inside Isample.cs
[OperationContract]
[WebGet(UriTemplate = "contacts?format=json", ResponseFormat = WebMessageFormat.Json)]
List<Contacts> GetContactListAsJson();
when I run this application I am getting a Json file .When I download opened that Json file using notpad and the format was like
[{"FirstName":"Bala","LastName":"Krishnan","PhoneNo":"91-9898789"},{"FirstName":"Ram","LastName":"Venkat","PhoneNo":"91-9854677"}]
I Search google and code project and found some serializing method and used
1. JavascriptSerializer
2. Newtonsoft Json
3. Datacontract Serialization
I also got result but it was like
[{\"FirstName\":\"Bala\",\"LastName\":\"Krishnan\",\"PhoneNo\":\"91-9898789\"},{\"FirstName\":\"Ram\",\"LastName\":\"Venkat\",\"PhoneNo\":\"91-9854677\"}]
What should I do to get result(d factor) like below mentioned when i open json file using notepad.
["0001":{
"FirstName":"Bala",
"LastName":"Krishnan",
"PhoneNo":"91-9898789"
},
"0002":{
"FirstName":"Ram",
"LastName":"Venkat",
"PhoneNo":"91-9854677"
}]
Thanks in Advance