tags:

views:

308

answers:

3

This is probably a really easy question, but I can't find anything that works.

I'm trying to take a json result and just write it into the inner html of a div to see what it looks like.

I have something like this:

$.getJSON("someurlthatgivesmejson",
    function(data){         
        $("#jsonmodel").html(data);  // what should this be??
    });
  });

UPDATE

I was able to get it to display some text by using

$("#jsonmodel").html($.param(data));

However, it's not formatted like how the browser displays a json result, like the structure of the javascript object.

+1  A: 

depends on what the data is. if you want to write it as a string, then you should use the $.get method to get it, that way its not converted into a js hash for you

mkoryak
Thanks, so I should do something like $("#jsonmodel").html($.get(data));?
Joseph
That's not working for me. I'm trying serialize as well but it doesn't work either.
Joseph
@Joseph: No, mkoryak meant `$.get("someurlthatgivesmejson")`
Crescent Fresh
@crescentfresh I thought he might have meant that as well and I tried that too. Still no dice. I'm starting to think what I'm trying to do is impossible.
Joseph
A: 

data is a JavaScript object, you need a string.

code_burgar
+1  A: 

You can use jquery-json library

`$('#jsonmodel').html($.toJSON(data));`
Jirapong
Is the library hosted by google by any chance? I'm trying to get this working on their API Playground
Joseph
No, I don't think so. may be you re-use code directly from http://code.google.com/p/jquery-json/source/browse/trunk/jquery.json.js
Jirapong
This plugin was helpful. Thanks for the link.
txyoji