Been playing with the API a fair bit now in terms of writing a C# port of it.

I tend to convert everything returned in JSON to an XmlDocument before manipulating it (Simply because I don't actually know how else to handle it within C#) However if I run any queries that return more than one result within the JSON, for example members/{:ID}/endorsements the XmlDocument parse fails as there are multiple root level elements read from the parser.

This to do with the structure that is returned from DaniWeb or the actual parser failing? I'm using the Newtonsoft.Json DLL (Aka JSON.Net) to parse to Xml. (Would expect its functionality to be well tested?)

Recommended Answers

All 15 Replies

Why don't you use JSON.net library. No need for creating ugly XMLs and parsing these again

That would be the library I am playing with. Tried using mapping from it to custom classes but it failed for some reason so went along the XML route. Inexperience is probably playing its role.

Have investigated further and it seems I can perform the same functionality using JObject and LINQ from the above suggested DLL. Will implement this instead, probably for the best anyway.

Case closed. For now.

I'm not sure what you mean about multiple root level elements? Of course, I want to make sure the data structure of the API is as conducive as possible for everyone moving forward.

It should return a single root level element with a data property that contains everything.

I'm not entirely sure what was causing it also in all honesty Dani as I can't see the output of the parse due to it failing, just know the exception was that there were multiple root levels. My only assumption is that it was stripping out the Data root that you have and trying to take each returned endorsement entry as a root node? Moved away from using XML now though.

I figured out that it doesn't like my arrays of IDs, so I'm going to have to go ahead and restructure them a little bit to no longer be arrays of IDs, but actually specify an 'id' parameter, if that makes any sense.

It'll make sense when I see the structure change im sure :)

Here's an example (work in progress):

{
 "data":[
  {
   "title":"Hardware and Software",
   "description":"Our Hardware and Software forum category encompasses topics related to end-user computer technical support troubleshooting, tips and tweaks. Please be sure to always post in the appropriate sub-forum and do not hijack existing threads with your own support issue; start a new thread instead.",
   "uri":"http:\/\/www.daniweb.com\/hardware-and-software\/1",
   "id":"1",
   "replies_count":"1033",
   "articles_count":"414",
   "last_post":{
    "timestamp":"1361423414"
   },
   "relatives":{
    "children":[
     {
      "id":"99"
     },
     {
      "id":"12"
     },
     {
      "id":"7"
     },
     {
      "id":"11"
     },
     {
      "id":"13"
     },
     {
      "id":"98"
     }
    ]
   }
  }
 ]
}

Instead of the children being an array of ID #s, they are now each their own object with an 'id' property. This way you can overlap each one of them with a Forum ID object.

Ooh I see what you mean now.

I've made some changes to the way that you pull forums so hopefully it's a LOT clearer when parents/children/descendants get fetched and how they get fetched. I also put an end to that double array thing that was going on.

Member Avatar for diafol

Aaaarghhhh!

Member Avatar for diafol

Clearer. Back to the loop :(

I'm trying to use you guys as test subjects to perfect the API. The changes I'm making are all in response to your feedback, so let me know if you think I'm going in the wrong direction, or if it seems like things are changing for no good reason.

Member Avatar for diafol

I agree with this change (I think I mentioned it in the main API thread - where I had to make a nested loop to get at the actual data). So all good. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.