2

I'm experiencing some difficulties when parsing a JSON object sent from AngularJS to Python (Google App Engine).

The AngularJS code:

var article = { name: 'car' };
$http.put("articles", article);

The python code:

# -*- coding: UTF-8 -*-

import os
import webapp2
import logging
import json 

class ArticleHandler(webapp2.RequestHandler):

    def put(self):
        data = self.request

        logging.error(data)
        #x = json.dumps(data)   
        #y = json.loads(data)

The error-log returns {"name":"car"}

json.dumps(data) raises: TypeError(repr(o) + " is not JSON serializable")

and

json.loads(data) raises: TypeError: expected string or buffer

Any help is appreciated

4

1 回答 1

1

您正在尝试将Request对象解析为 json 数据。尝试解析正文:

json.loads(self.request.body)

于 2013-09-27T22:09:44.130 回答