0

I am getting some data from Gov tracker (http://www.govtrack.us/developers/api) and creating a Windows 8 Store application..

I started out trying to use the HttpClient to get the JSON and then use Json2Charp.com to convert it to classes... But then I had no idea what to do with this giant class and the line

  var contacts = JsonArray.Parse(data);

would not work..

So now I requested it as XML and I am using XML to LINQ to slowly get what I need ..for example..

    var things = from x in xdoc.Descendants("person")
                     select new Person
                     {
                         firstname = x.Element("firstname").Value
                     };

But in this case and in general what is the easiest way? Is it using XML for this windows 8 application and using JSON to javascript applications? (since I always hear about how JSON fits so well with javascript)

At the moment since I could not get the JSON deserialization to work I guess XML is easier in this case?

1

1 Answer 1

1

I'm going to bet that the data retrieved from most REST URLs is a JSON object, not an array. The distinction is something like this:

array===> [1, 2, 3, 4]
object containing an array===> { "numbers": [1, 2, 3, 4] }

I don't know the library you're using, but I'm betting the method you're looking for is JsonObject.Parse(data), and then something to retrieve the specific property you want (ie, "numbers" above). You could edit your post with some sample text data if you want us to confirm. I would recommend if the data is not public, then replace the actual values with made-up stuff to maintain data privacy.

Which one is easier to use may depend on what you're used to, or which developers you tend to work with. Many would argue in favor of JSON, since it could be easier to program for, supports arrays directly, and it tends to have less of a network footprint. Still, it does seem to be a not-so-consequential matter of preference and your app could certainly work fine just using XML. (There may also be some data types more easily represented in an XML-based format; for instance, declarative UI languages like HTML)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.