Returning JSON object from an ASP.NET page

Posted by Emin on Stack Overflow See other posts from Stack Overflow or by Emin
Published on 2010-03-11T06:19:03Z Indexed on 2010/03/11 19:19 UTC
Read the original article Hit count: 209

Filed under:
|

Hi,

In my particular situation, I have couple of solutions to my problem. I want to find out which one is more feasible. In this case, I can also achieve my goal by returning a JSON object from my server side code, however, I do not know how it is done and what is the best way of doing it.

First off, I don't need a full aspx page as I only need a response returned from code. So, do I use web services? handler? or is there any other specific way you people do this?

Is this solution feasible? do I build the JSON string using the StringBuilder class and inject that string into the target aspx page? are there any precautions? or things that I should be aware of?

I appreciate your ideas.

Regards,

Kemal

------------UPDATE !------------

Suppose I have a JSON object in my userlist.aspx page. which then I use it with jQuery...

{"menu": {
  "id": "color1",
  "value": "color",
  "popup": {
    "menuitem": [
      {"value": "Red"},
      {"value": "Green"},
      {"value": "Yellow"}
    ]
  }
}} // example taken from the json.org/example page

now when I want to add a new menuitem from my aspx page, what do I do... I think this way my question is more specific... Lets assume I create a new string in my aspx code, as such "{"value": "Blue"}. Now how do I inject this into the already existing itemlist in the target page? or is this not the correct approach to this kind of situation? if not how else can it be achieved? Also if I wanted to fire a jquery event when a new item is added to this list, how is this achieved?

© Stack Overflow or respective owner

Related posts about JSON

Related posts about ASP.NET