SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Miguel61's Avatar
    Join Date
    Mar 2008
    Posts
    402
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    How to Convert XML to a JSON

    Hi all, I hope in your help.

    I need consume a web service ASP.NET in Android and convert XML output to JSON for correct output in mobile device.

    This is my webservice and the error is:
    Code:
    Cannot implicitly convert type 'string' to 'System.Xml.XmlDocument'
    Can you help me?
    Thanks in advance.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Web;
    using System.Web.Services;
    using System.Data;
    using System.Data.Odbc;
    using System.Configuration;
    using System.Xml;
    using System.Web.Script.Serialization;
    using System.Text;
    using System.Web.Script.Services;
    using Newtonsoft.Json;
    
    [WebService(Namespace = "http://www.XXXXX.com/WebService")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class WebService : System.Web.Services.WebService
    {
    
        public XmlDocument GetCustomers()
        {
            XmlDocument doc =
                new XmlDocument();
    
            DataSet YourTableDataSet =
                new DataSet("WebService");
    
            using (OdbcConnection conn =
                new OdbcConnection(ConfigurationManager.ConnectionStrings["cs"].ConnectionString))
            {
                OdbcDataAdapter adapter =
                    new OdbcDataAdapter("SELECT * FROM tbl;", conn);
                adapter.Fill(YourTableDataSet, "WebService");
            }
    
            doc.LoadXml(YourTableDataSet.GetXml());
    
            return JsonConvert.SerializeXmlNode(doc, Newtonsoft.Json.Formatting.Indented);
        }
    }

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,629
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Mobile devices read XML just fine. Nothing outside of .NET reads serialized datasets too well -- you should probably take the step of building an object graph, serializing that and sending that down the wire.


Bookmarks

Posting Permissions

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