simplejson

SimpleJSON and NumPy array

拜拜、爱过 提交于 2019-12-17 15:22:20
问题 What is the most efficient way of serializing a numpy array using simplejson? 回答1: I'd use simplejson.dumps(somearray.tolist()) as the most convenient approach (if I was still using simplejson at all, which implies being stuck with Python 2.5 or earlier; 2.6 and later have a standard library module json which works the same way, so of course I'd use that if the Python release in use supported it;-). In a quest for greater efficiency, you could subclass json.JSONEncoder (in json ; I don't know

Get corresponding value from json key in python

喜你入骨 提交于 2019-12-16 18:02:27
问题 currently I have the following which parses a json api.. import simplejson import urllib2 f = urllib2.urlopen('http://fanart.tv/webservice/series/f5b8e776c35e7536eac132802b03281f/80349/json/tvthumb/') data = simplejson.load(f) imagetypes = ['clearlogo', 'clearart', 'tvthumb', 'seasonthumb', 'characterart'] image_list = [] # split "name" and "data" for title, value in data.iteritems(): # run through specified types for art in imagetypes: # if type has been found if value.has_key(art): # Run

simplejson returns values not in order [duplicate]

帅比萌擦擦* 提交于 2019-12-13 01:43:47
问题 This question already has answers here : Items in JSON object are out of order using “json.dumps”? (6 answers) Closed 6 years ago . When working with simplejson in Django, I sometimes need to send the information strictly in order. values = {"entry1":"value1","entry2":"value2","entry3":"value3"} return HttpResponse(simplejson.dumps(values),content_type="application/json") That's what it returns {"entry2": "value2", "entry3": "value3", "entry1": "value1"} But I want it to returns this instead:

Various errors while parsing JSON in Python

穿精又带淫゛_ 提交于 2019-12-12 16:20:35
问题 Attempting to parse json from a url requiring login. Including all my code here as I'm not sure where the error is. try: import simplejson as json except ImportError: import json import urllib2 username = 'user' password = '1234' url = "https://www.blah.com/someplace" # set up the username/password/url request password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() password_mgr.add_password(None, "https://www.blah.com", username, password) handler = urllib2.HTTPBasicAuthHandler(password_mgr)

In Google app engine dev server, simplejson.dumps is sending data that contains header info that reads True,0,1

跟風遠走 提交于 2019-12-12 03:22:51
问题 The problem was with print statements. In app engine avoid print, use logger. I have a python dict containing unicode strings. I need to send the dict to the javascript code to do page refresh. I am doing something like this. map=getMap() return Response(simplejson.dumps(map)) In the javascript code how ever I get following response, True,0,1,2........... {map data}. I was expecting only {map data} not True,0,1,2... as prefix. Do you know why is this happening. It only happens when there is

How to include annotation in JSON string?

流过昼夜 提交于 2019-12-11 17:26:14
问题 I've got a view that returns a list of shipments encoded as JSON... def get_new_shipments(request): # ... shipments = Shipment.objects.filter(filter).exclude(**exclude).order_by(order) \ .annotate(num_bids=Count('bids'), min_bid=Min('bids__amount'), max_bid=Max('bids__amount')) return json_response(shipments) def json_response(data): response = HttpResponse(mimetype='application/json') serializer = serializers.get_serializer("json")() data = list(data) serializer.serialize(data, ensure_ascii

Simplejson and random key value

核能气质少年 提交于 2019-12-11 14:08:33
问题 Here is the value i got from API server {"query":{"pages":{"-1":{"ns":0,"title":"spencerx","missing":""}}}} Let say if i want to get determine if it's not missing word, i will know by looking at "-1" of the return. but when the word exist, it will returning me the following json {"query":{"pages":{"1080152":{"pageid":1080152,"ns":0,"title":"spencer"}}}} which is a random number. may i know how could i detect that's '-1' and determine the word doesn't exist? while i try to print x['query'][

Converting a string to JSON in C#

我只是一个虾纸丫 提交于 2019-12-09 16:26:36
问题 I'm trying to use Simple JSON to convert this string to JSON : "{\"objects\":[{\"id\":1,\"title\":\"Book\",\"position_x\":0,\"position_y\":0,\"position_z\":0,\"rotation_x\":0,\"rotation_y\":0,\"rotation_z\":0,\"created\":\"2016-09-21T14:22:22.817Z\"},{\"id\":2,\"title\":\"Apple\",\"position_x\":0,\"position_y\":0,\"position_z\":0,\"rotation_x\":0,\"rotation_y\":0,\"rotation_z\":0,\"created\":\"2016-09-21T14:22:52.368Z\"}]}" Unfortunately, it appears that Visual Studio doesn't have Interactive

How to solve the ImportError: cannot import name simplejson in Django

一曲冷凌霜 提交于 2019-12-09 14:49:27
问题 I'm trying to build a realtime chat app in Django(1.7.1). It seems that I needed to install Redis and ishout.js. So I installed them by following the instructions. After making the project in Django, I put 'drealtime' under the INSTALLED_APPS, and put: 'drealtime.middleware.iShoutCookieMiddleware' right above : 'django.contrib.sessions.middleware.SessionMiddleware' under the MIDDLEWARE_CLASSES as it was saying. And I put the command like python manage.py startapp example but still I have this

django escapejs and simplejson

心不动则不痛 提交于 2019-12-08 19:46:12
问题 I'm trying to encode a Python array into json using simplejson.dumps: In [30]: s1 = ['test', '<script>'] In [31]: simplejson.dumps(s1) Out[31]: '["test", "<script>"]' Works fine. But I want to escape the strings first (using escapejs from Django) before calling simplejson.dumps: In [35]: s_esc Out[35]: [u'test', u'\\u003Cscript\\u003E'] In [36]: print simplejson.dumps(s_esc) ["test", "\\u003Cscript\\u003E"] My problem is: I want the escaped string to be: ["test", "\u003Cscript\u003E"] instead