0

I have a problem with Json formating returned from .ASMX

I need to return something like this

[{ name : "TEST1", data : [100]},
{ name : "TEST2", data : [200]}]

so here's my sample

 [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
    public List<jsonGraphSeries> Graph(string ID)
    {
       List<GenList>objGenList = new List<GenList>();
       GenList objlist;

       objlist = new GenList();
       objList.name = "TEST";
       objList.data[0] = 100;
       objGenList.add(objList);
     }



public class GenList
{
 public string name;
 public double[] data;
}

and nothing happens... can someone help me with this?

Leary
  • 117
  • 1
  • 3
  • 10
  • Are you making sure it's a HTTP POST request? See this: http://stackoverflow.com/questions/211348/how-to-let-an-asmx-file-output-json – greg84 Jun 29 '12 at 09:32
  • I just want to make a json w/c can output in this format – Leary Jul 01 '12 at 23:36

2 Answers2

1

Your method isn't returning anything, does adding this this work?

return objGenList;

greg84
  • 7,541
  • 3
  • 36
  • 45
1

silly me... in order for the json to recognize it as an array field...

instead of doing this...

objList.data[0] = 100;

I should've done it like this...

 objlist = new GenList();
 objList.name = "TEST";
 objList.data = new [] {100};
 objGenList.add(objList);

the output would be

{ name : "TEST1", data : [100]}
Leary
  • 117
  • 1
  • 3
  • 10