from jsonrpc import json
users = context.sql_search_users(keyword = context.REQUEST.get('keyword'))
fields = users.data_dictionary().keys()
userArray = []
for user in users:
userDict = {}
for field in fields:
userDict[field] = user[field]
userArray.append(userDict)
return json.dumps(userArray)
Zope Python Script JSON Serialize a result set object
The Python JSON-RPC library doesn't allow direct serialization of a result set object.
But, you can iterate over the rows and fields of the result set dynamically to produce an object that can be serialized to JSON.
But, you can iterate over the rows and fields of the result set dynamically to produce an object that can be serialized to JSON.
Snippet Viewed 3687 times.
Share your Zope Python Script code snippets:
- Get some recognition & a link back to your site.
- Create your own code library.
- Help your fellow developers, as they have helped you.