0

My Problem is that when I browse to the service URL I see "key-value" pairs but I don't see the name of the array or object, I need the name because I want to use that service for android.

it looks like this: enter image description here

My code looks like this:

1. In ValueController I have method:

[AcceptVerbs("GET", "POST")]   
public List<BuzzMonitor.Web.Message> Search(string text, DateTime dateFrom, DateTime dateTo, [ModelBinder]List<int> themeIds, [ModelBinder]List<int> sourceIds)
{
    MessageHandler mh = new MessageHandler();

    List<BuzzMonitor.Web.Message> messages = null;

    messages = mh.Search(text,dateFrom,dateTo,themeIds,sourceIds);

    return messages;
}

2. In Global.asax I added:

GlobalConfiguration.Configuration.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));

Does anyone have an idea on what is missing when I don't see full JSON, and see just key:value pairs? Thank you for help!

BenjaminPaul
  • 2,931
  • 19
  • 18
MalaAiko
  • 151
  • 4
  • 11

1 Answers1

2

I think you are thinking that you are not seeing the array name or class right? and that is an error?

The answer is NO.

Reason? Well, JSON was invented to share objects easily over network and the main goal was to make it independent of the underlying architecture -

http://www.json.org/

that is why you don't see array names or variable names, only the object notation. Thats JSON stands for Java Script Object Notation. It's the responsibility of the receiving side to re-construct the object from the data provided in json format.

in your case messages is an array with a list of data and so does the output -

[] means array and {} inside that means it has only one object in it.

EDIT: You can also use this to parse json -

http://developer.android.com/reference/org/json/JSONTokener.html

brainless coder
  • 6,310
  • 1
  • 20
  • 36
  • Yes, you undrestood me good. Now, I need to see array name, do you know how to accomplish that? Because from android app I need to go on this service, and then to take data. I need to see array name because I will need to parse JSon... Android is very strict in that case, and If I dont have arrayName I couldn't take value based on key. Sorry if cant explain you well what I want to accomplish. – MalaAiko Jun 02 '14 at 09:30
  • You don't need array name, just parse the data and load it in an array variable. This might help - http://stackoverflow.com/questions/5566669/how-to-parse-a-json-object-in-android – brainless coder Jun 02 '14 at 09:36
  • There is no need to have the array name in Android in order to parse it. It will work just fine without it! – BenjaminPaul Jun 02 '14 at 09:39