First, you don't need to explicitly specify the validator, but if you do,
it should be IS_JSON(). Second, once you select a record, you do not need
to pass the resulting value to json.loads() -- web2py will automatically
convert the stored JSON value to a Python object (that's the point of the
JSON field type).
Anthony
On Sunday, March 30, 2014 12:59:11 PM UTC-4, mweissen wrote:
> Sorry, I did not test all cases.
> E.g.:
>
> Field ('url', 'json', requires=IS_JSON)
> ...
> res = db(db.mydb.id==1).select().first()
> print json.loads(res.url)
>
>
> Again res.url is something like
> {'u'f : u'testfunction' ... }
>
> and URL(**res.url) fails.
>
>
>
> 2014-03-30 18:21 GMT+02:00 Martin Weissenboeck <[email protected]>:
>
>> That's the answer! I have forgotten the "json" type parameter, I had only
>> requires=IS_JSON()
>> I have tried it again and now it works. Thank you!
>>
>>
>>
>>
>> 2014-03-30 15:10 GMT+02:00 Anthony <[email protected]>:
>>
>> Have you tried:
>>>
>>> Field('url', 'json')
>>>
>>> Anthony
>>>
>>> On Saturday, March 29, 2014 7:11:34 PM UTC-4, mweissen wrote:
>>>
>>>> Let's say I have
>>>> URL(f="myfunction", vars=dict(x=1))
>>>> or
>>>> v = {"f":"myfunction", "vars":{"x":1}}
>>>> URL(**v)
>>>>
>>>> That works fine.
>>>>
>>>> Now I do
>>>> j = json.dumps(v)
>>>>
>>>> I store j in
>>>> Field("url", requires=IS_JSON())
>>>>
>>>> Now I read this field and call URL(**fieldvalue). I get an error:
>>>>
>>>> <type 'exceptions.SyntaxError'> when calling URL, function or function
>>>> name required
>>>>
>>>> The fieldvalue I get is
>>>> {'u'f : u'festfunction' ... }
>>>>
>>>> The key is a unicode string and not utf-8 coded.
>>>>
>>>> What is wrong? How can I get an utf-8 string?
>>>>
>>>> Regards, Martin
>>>>
>>>>
>>
>>
>>
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.