Results 1 to 2 of 2

Thread: JSON Being Returned from asmx web service ScriptMethod

  1. #1
    Sencha User
    Join Date
    Nov 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default JSON Being Returned from asmx web service ScriptMethod

    I have created a c# web service to return JSON for some of our SharePoint data. Below is the web service code:

    [WebMethod]
    [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
    Ext.setup(
    {
    fullscreen: true,
    glossOnIcon: false,
    onReady: function ()
    {
    // to test the call
    Ext.Ajax.request(
    {
    url: 'https://mobile.*****.com/spclient/webservice.asmx/GetJSON',
    method: 'GET',
    jsonData: { "Alert": {} },
    headers: { 'Content-Type': 'application/json;charset=utf-8'
    },
    success: function (response, opts)
    {
    console.log(response.responseText);
    },
    failure: function (response, opts)
    {
    console.log(response.responseText);
    }
    })
    }
    })


    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.

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    Is this 193 characters long? Did you decode it via Ext.decode(response.responseText) ?
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •