Link to home
Start Free TrialLog in
Avatar of Black_Trash
Black_Trash

asked on

web service asmx to return json without "<string xmlns="http://tempuri.org/">" tacked on to

Built a web service and the output has "<string xmlns="http://tempuri.org/">" tagged on to the top of the output.  Trying to read the output with jQuery and I think "<string xmlns="http://tempuri.org/">" causing the jQuery to have problems parsing the data.

 The c# code in the web service is the following:
                        [WebMethod]
                        [ScriptMethod(ResponseFormat = ResponseFormat.Json)]

......................................................
      da.Fill(ds, "Inventory");
                                    sqlConnection1.Close();
                                    XmlDataDocument doc = new XmlDataDocument(ds);
                                    string jsonStr = JsonConvert.SerializeXmlNode(doc);
                        //            JavaScriptSerializer jsonstuff = new JavaScriptSerializer();
                                    return jsonStr;

Sample of the string out:
<string xmlns="http://tempuri.org/">
{"NewDataSet":{"Inventory":[{"MOVE_ID":"577","FeedyardID":"3","Lot":"103","Pen":"103 ","MoveDate":"2011-04-25T00:00:00-

What do I need to do to get rid of the <string xmlns="http://tempuri.org/"> or enable jQurey to parse the data into the correct fields?



Thanks,
Keith
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Black_Trash
Black_Trash

ASKER

Thank you both for helping me.

After doing some digging around on my $.ajax and maybe the combination of adding
to the system.webServer section of the client program config.system system.webServer section:
            <handlers>
            <add name="ScriptHandlerFactory"
                 verb="*" path="*.asmx"
                 type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                 resourceType="Unspecified" />
        </handlers>
            </system.webServer>

I was able to parse the JSON string and then break out the record fields.
                                    var obj = $.parseJSON(Some_data);
                                    alert("Parsed =" + obj.NewDataSet.Inventory[0].MOVE_ID);
Just as a note I used the following for the AJAX call:
                                    $.ajax({
                                                type: 'POST',
                                                contentType: "application/json; charset=utf-8",
                                                dataType: 'json',
                                                url: MYurl,
                                                data: "{}",
                                                success:function (data) {
                                                            strData = data.d;
                                                            parseData(strData);
                                                },
                                                error: function (a) {
                                                            alert(a.responseText);
                                                }
                                    });

In the above is not perfect, still has some test items in it, but it works.

Thank you both for helping me out.

Thanks,
Keith Black
You are welcome Keith, thanks for the points.