View Full Version : JSON Being Returned from asmx web service ScriptMethod

7 Nov 2011, 7:20 AM
I have created a c# web service to return JSON for some of our SharePoint data. Below is the web service code:

[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true, XmlSerializeString = false)]
public string GetJSON() {
ExecutiveTeamDataContext dc = new ExecutiveTeamDataContext(new Uri("http://connect.xxxxx.com/workgroups/ec/_vti_bin/listdata.svc"));
dc.Credentials = new NetworkCredential("xxxxx", "xxxxx", "xx");
var items = from c in dc.WorkgroupTasks where c.Id == 10
select new
TaskID = c.Id,
TaskTitle = c.Description1,
TaskNextAction = c.NextActionStatus,

JavaScriptSerializer js = new JavaScriptSerializer();
string strJson = js.Serialize(items);
return strJson;

Following is what is being returned to sencha

{"d":"[{\"TaskID\":10,\"TaskTitle\":\"\u003cdiv\u003eAnalysis of Capital Accounts\u003c/div\u003e\",\"TaskNextAction\":\"\u003cdiv\u003eUse model to develop presentation to bonding company.\u003c/div\u003e\"}]"}

Here is the code I used to read the response
fullscreen: true,
glossOnIcon: false,
onReady: function ()
// to test the call
url: 'https://mobile.*****.com/spclient/webservice.asmx/GetJSON',
method: 'GET',
jsonData: { "Alert": {} },
headers: { 'Content-Type': 'application/json;charset=utf-8'
success: function (response, opts)
failure: function (response, opts)

Finally, here is the code I am using to try to bind the data. When it runs, I get a count in the console of 193 records, even though the web service is returning only the one record shown above. Also, nothing is displayed in the grid, just 193 empty rows. My guess is that it has something to do with the " directly after "d" : " since many of the examples I have seen do not include this. So if the root is d, it seems like everything else is being wrapped in an extra pair of quotes.

18 Nov 2011, 3:18 PM
Is this 193 characters long? Did you decode it via Ext.decode(response.responseText) ?