Before sending the data to the page element, you could do this at
controller or view:

data = dumped[1:-1] to remove the array notation

Anyway, something is wrapping the object inside an array. Is that the
default behavior?

On Feb 15, 2:07 am, Vineet <[email protected]> wrote:
> In controller, I prepare a json object :--
>
> import simplejson
> D = {'a':1.23, 'b':'xyz'}
> jsonD = simplejson.dumps(D, as_decimal=True)
>
> This json object is sent to the browser.
> An HTML input element is populated with this json object.
> In the input box within the browser, it looks like this --->
>
> [{"a":"1.23", "b":"abc"}]
> (pl. note the [] brackets.
> I was expecting something like this --->
>
> {"a":"1.23", "b":"abc"}
>
> (if the code is run in python shell, [ ] are not there).
>
> So in javascript code, for accessing a value, I need to parse it like
> this:
>
> var txds = JSON.parse($('#json_input').val());
> alert(txds[0]['a']);
>
> instead of this:
>
> alert(txds['a']);
>
> How do I avoid the [ ]? (if possible)
>
> Thanks,
>
> Vineet

Reply via email to