Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192447
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:56:32+00:00 2026-05-28T19:56:32+00:00

I have this code, but can’t get it all working. I am trying to

  • 0

I have this code, but can’t get it all working.

I am trying to get a json string into xml. So that I can get a list of items when i parse the data. Is there a better way to parse json into xml.

If so what’s the best way to do it, and if possible could you give me a working example?

The URL that is in the code is not the URL that i am using

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Utilities;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Schema;
using Newtonsoft.Json.Bson;
using System.Xml;
using System.Xml.Serialization;
using System.Xml.Linq;
using System.Xml.Linq.XDocument;
using System.IO;



namespace WindowsPhonePanoramaApplication3
{
public partial class Page2 : PhoneApplicationPage
{
    public Page2()
    {
        InitializeComponent();
    }


    private void Form1_Load(object sender, EventArgs e1)
    {
        /* because the origional JSON string has multiple root's this needs to be added */
        string json = "{BFBC2_GlobalStats:";
        json += DownlodUrl("http://api.bfbcs.com/api/xbox360?globalstats");
        json += "}";

        XmlDocument doc = (XmlDocument)JsonConvert.DeserializeObject(json);
        textBox1.Text = GetXmlString(doc);
    }

    private string GetXmlString()
    {
        throw new NotImplementedException();
    }


    private string DownlodUrl(string url)
    {
        string result = null;
        try
        {
            WebClient client = new WebClient();
            result = client.DownloadString(url);
        }
        catch (Exception ex)
        {
            // handle error
            result = ex.Message;
        }
        return result;
    }

    private string GetXmlString(XmlDocument xmlDoc)
    {
        sw = new StringWriter();
        XmlTextWriter xw = new XmlTextWriter(sw);
        xw.Formatting = System.Xml.Formatting.Indented;
        xmlDoc.WriteTo(xw);
        return sw.ToString();
    }

        }
}

The URL outputs the following code:

{"StopName":"Race Hill",
"stopId":7553,
"NaptanCode":"bridwja",
"LongName":"Race Hill",
"OperatorsCode1":" 5",
"OperatorsCode2":" ",
"OperatorsCode3":" ",
"OperatorsCode4":"bridwja",
"Departures":[
{
"ServiceName":"",
"Destination":"",
"DepartureTimeAsString":"",
"DepartureTime":"30/01/2012 00:00:00",
"Notes":""}`

Thanks for your responses. So Should i just leave the data a json and then view the data via that???

Is this a way to show the data from a json string.

public void Load()
{
// form the URI
UriBuilder uri = new UriBuilder("http://mysite.com/events.json");
WebClient proxy = new WebClient();  
proxy.OpenReadCompleted += new OpenReadCompletedEventHandler(OnReadCompleted);  
proxy.OpenReadAsync(uri.Uri);  
}

void OnReadCompleted(object sender, OpenReadCompletedEventArgs e)
{
if (e.Error == null)
{
var serializer = new DataContractJsonSerializer(typeof(EventList));
    var events = (EventList)serializer.ReadObject(e.Result);
    foreach (var ev in events)
{
Items.Add(ev);
}
}
}

public ObservableCollection<EventDetails> Items { get; private set; }

Edit:
Have now kept the url as json and have now got it working by using the json way.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:56:33+00:00Added an answer on May 28, 2026 at 7:56 pm

    I’m not sure why you want to convert it into XML, why not just parse directly into objects?

    Use something like http://json2csharp.com/ to generate your classes. Then use the DataContractJsonDeserializer to read the Json into the objects. For an example of how to go about that bit, please see this MSDN article.

    Edt again : Ah, I see you are already using Newtonsoft.JSON – that is a good alternative to the built-in deserialisation. You can use that to deserialise to a set of objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code that is working, but how can I load item value
I have been working on this code but I can't find out what is
I have this code to update users data, but I can't write the for
I have the following code to do this, but how can I do it
I have this code that works in a unit test but doesn't work when
I have this code which gets WP posts, but it gets all the posts
I have this code but I just can't understand it. using System; using System.Collections.Generic;
I have this code where I'm trying to get the current date and format
i have this code but i can't see the action when i click on
i have this code it can go to if(array_key_exists('p',$_POST)) but can't go to if(isset($_POST['p'][$i])

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.