views:

26

answers:

0

Hi all!

I'm developing an application in C# which can control a SqueezeboxServer(SBS). Communicating to the SBS is via JSON messages to http://serverIP:9000/jsonrpc.js So I send JSON messages via a HTTPWepRequest and get answers via an HTTPWebResponse.

The answer I get is a String in JSON notation. And this is where the problems start... For now I convert the JSON message to a Object with the JavaScriptSerializer. This goes like this:

public static Object FromJSON(this string reply)
{
    JavaScriptSerializer deSerializer = new JavaScriptSerializer();
    return deSerializer.DeserializeObject(reply);
}

This code gives me an object which holds the data I ask for. The data I ask for can be very different. Sometimes the answer is a single answer while in other situations it can be multiple things.

Let's consider the two images I've included:

The first one shows the object after it has been returned by the deSerializer. You can see the object is a Dictionary with 4 key-value pairs. The kvp I'm interrested in, is the 4th one. The key "result" is the one which hold the data I need. But this key has another Dictonary as a value. And this goes on and on until the actual data I want, which is the album name and its ID.

alt text

In the second image the data I want is the value 0 which belongs to the "_count" key. As you can see, this object is less complicated.

alt text

So the bottomline of my question is how do I make a solution which can retrieve the information I want but works with differt kind of objects (as in different depths)?

Hope anybody can send me in the right direction.

Thanks!