On 4 Mar 2014, at 7:52 AM, Avi A <[email protected]> wrote:
> thanks,
> i've tried it but I am not able to parse it:
> I tried both:
> pivotal = json.loads(r.content)
>
> session.flash(pivotal['url'])
> session.flash(pivotal[0].url)
Odd:
>>> s = """{
... "owner_ids": [
...
... ],
... "labels": [
... {
... "id": 7864106,
... "created_at": "2014-03-04T10:39:27Z",
... "project_id": 941736,
... "name": "label",
... "kind": "label",
... "updated_at": "2014-03-04T10:39:27Z"
... }
... ],
... "current_state": "unscheduled",
... "id": 66856110,
... "created_at": "2014-03-04T13:31:33Z",
... "story_type": "bug",
... "project_id": 941736,
... "name": "title",
... "url": "http://www.pivotaltracker.com/story/show/66856110",
... "kind": "story",
... "updated_at": "2014-03-04T13:31:33Z",
... "requested_by_id": 735355,
... "description": "story http://google.com/105"
... }
... """
>>> import json
>>> json.loads(s)
{u'story_type': u'bug', u'kind': u'story', u'name': u'title', u'url':
u'http://www.pivotaltracker.com/story/show/66856110', u'created_at':
u'2014-03-04T13:31:33Z', u'labels': [{u'kind': u'label', u'name': u'label',
u'created_at': u'2014-03-04T10:39:27Z', u'updated_at': u'2014-03-04T10:39:27Z',
u'project_id': 941736, u'id': 7864106}], u'current_state': u'unscheduled',
u'updated_at': u'2014-03-04T13:31:33Z', u'requested_by_id': 735355,
u'description': u'story http://google.com/105', u'project_id': 941736, u'id':
66856110, u'owner_ids': []}
>>> j = json.loads(s)
>>> j['url']
u'http://www.pivotaltracker.com/story/show/66856110'
>
>
>
> On Tuesday, March 4, 2014 5:18:02 PM UTC+2, Jonathan Lundell wrote:
> On 4 Mar 2014, at 5:35 AM, Avi A <[email protected]> wrote:
>> Hi,
>> I'm getting on a controller a json response as expected, and I didn't find a
>> way how to parse it yet:
>
> json.loads(r.content) will convert it to a dict.
>
>>
>> r = requests.post(url, data=json.dumps(payload), headers=headers)
>> r.content returns something like that:
>> {
>> "owner_ids": [
>>
>> ],
>> "labels": [
>> {
>> "id": 7864106,
>> "created_at": "2014-03-04T10:39:27Z",
>> "project_id": 941736,
>> "name": "label",
>> "kind": "label",
>> "updated_at": "2014-03-04T10:39:27Z"
>> }
>> ],
>> "current_state": "unscheduled",
>> "id": 66856110,
>> "created_at": "2014-03-04T13:31:33Z",
>> "story_type": "bug",
>> "project_id": 941736,
>> "name": "title",
>> "url": "http://www.pivotaltracker.com/story/show/66856110",
>> "kind": "story",
>> "updated_at": "2014-03-04T13:31:33Z",
>> "requested_by_id": 735355,
>> "description": "story http://google.com/105"
>> }
>>
>> Thanks.
>>
>>
>> --
>> 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/groups/opt_out.
>
>
>
> --
> 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/groups/opt_out.
--
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/groups/opt_out.