本文整理汇总了Python中pyaid.json.JSON.JSON.fromString方法的典型用法代码示例。如果您正苦于以下问题:Python JSON.fromString方法的具体用法?Python JSON.fromString怎么用?Python JSON.fromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyaid.json.JSON.JSON
的用法示例。
在下文中一共展示了JSON.fromString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _writeError
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def _writeError(self, data):
""" Writes import error data to the logger, formatting it for human readable display. """
source = {}
if 'data' in data:
for n,v in DictUtils.iter(data['data']):
source[' '.join(n.split('_')).title()] = v
indexPrefix = ''
if 'index' in data:
indexPrefix = ' [INDEX: %s]:' % data.get('index', 'Unknown')
result = [
'IMPORT ERROR%s: %s' % (indexPrefix, data['message']),
'DATA: ' + DictUtils.prettyPrint(source)]
if 'existing' in data:
source = {}
snapshot = data['existing'].snapshot
if snapshot:
snapshot = JSON.fromString(snapshot)
if snapshot:
for n,v in DictUtils.iter(snapshot):
source[' '.join(n.split('_')).title()] = v
result.append('CONFLICT: ' + DictUtils.prettyPrint(source))
if 'error' in data:
self._logger.writeError(result, data['error'])
else:
self._logger.write(result)
示例2: _parseData
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def _parseData(self, data):
if not data:
return None
try:
return JSON.fromString(data)
except Exception, err:
return data
示例3: get
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def get(cls, url, config):
"""Returns the embedding object for the specified URL and config."""
try:
req = requests.get(config['url'] + '?url=' + urllib2.quote(url) + '&format=json')
return JSON.fromString(req.text)
except Exception, err:
return None
示例4: _loadBuildSnapshot
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def _loadBuildSnapshot(self):
settings = SettingsConfig(CompilerDeckEnvironment.projectSettingsPath, pretty=True)
snap = settings.get(['BUILD', 'LAST_SNAPSHOT'])
if snap is None:
return
try:
self._buildSnapshot = JSON.fromString(snap)
except Exception, err:
pass
示例5: _populateTools
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def _populateTools(self):
"""Doc..."""
path = self.getAppResourcePath('ToolsManifest.json', isFile=True)
try:
f = open(path)
definition = JSON.fromString(f.read())
f.close()
except Exception, err:
self.log.writeError('ERROR: Unable to read tools manifest file.', err)
return
示例6: _populateTools
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def _populateTools(self):
"""Doc..."""
path = self.getAppResourcePath('ToolsManifest.json', isFile=True)
try:
f = open(path)
definition = JSON.fromString(f.read())
f.close()
except Exception as err:
self.log.writeError('ERROR: Unable to read tools manifest file.', err)
return
for tool in ArgsUtils.getAsList('tools', definition):
self._addTool(tool)
self._toolBox.layout().addStretch()
示例7: _getEnvValue
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def _getEnvValue(cls, key, defaultValue =None, refresh =False, error =False):
if cls._ENV_SETTINGS is None or refresh:
if not cls.settingsFileExists():
print('WARNING: No environmental settings file found.')
return defaultValue
envPath = cls.getRootLocalResourcePath(cls._GLOBAL_SETTINGS_FILE, isFile=True)
f = open(envPath, 'r+')
try:
res = f.read()
except Exception:
print('ERROR: Unable to read the environmental settings file at: ' + envPath)
return
finally:
f.close()
try:
settings = JSON.fromString(res)
except Exception:
print('ERROR: Unable to parse environmental settings file at: ' + envPath)
return
cls._ENV_SETTINGS = settings
else:
settings = cls._ENV_SETTINGS
if key is None:
return settings
if StringUtils.isStringType(key):
key = [key]
value = settings
for k in key:
if k in value:
value = value[k]
else:
if error:
raise Exception('Missing environmental setting: ' + str(key))
return defaultValue
return value
示例8: handle
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def handle(self):
try:
data = self.rfile.readline().strip()
self._log.write('HANDLE: ' + str(data))
try:
result = self._respondImpl(JSON.fromString(unquote(data)))
except Exception as err:
self._log.writeError('RESPOND FAILURE', err)
if self.returnResponse:
self.wfile.write(JSON.asString({'error':1}))
return
if self.returnResponse:
out = {'error':0}
if result:
out['payload'] = result
self.wfile.write(out)
except Exception as err:
self._log.write('HANDLE FAILURE', err)
return
示例9: __init__
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def __init__(self, request, rootPackage =None, **kwargs):
""" Creates a new ApiRouterView instance.
@param rootPackage - The root package in which the router will import views. By default
the module will look in same package as the router class. Packages can be absolute,
or relative to the current package. """
super(ApiRouterView, self).__init__(request, **kwargs)
# Determine root package
self._root = rootPackage if rootPackage else ClassUtils.getModulePackage(self.__class__, 1)
zargs = self.getArg('zargs', None)
if zargs:
try:
self._zargs = JSON.fromString(zargs)
except Exception as err:
self._zargs = None
else:
self._zargs = None
self._signature = StringUtils.toUnicode(self.getArg('sig', ''))
self._incomingTimestamp = None
self._outgoingTimestamp = None
示例10: open
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
if not cls.settingsFileExists():
print 'WARNING: No environmental settings file found.'
return defaultValue
envPath = cls.getRootLocalResourcePath(cls._GLOBAL_SETTINGS_FILE, isFile=True)
f = open(envPath, 'r+')
try:
res = f.read()
except Exception, err:
print 'ERROR: Unable to read the environmental settings file at: ' + envPath
return
finally:
f.close()
try:
settings = JSON.fromString(res)
except Exception, err:
print 'ERROR: Unable to parse environmental settings file at: ' + envPath
return
cls._ENV_SETTINGS = settings
else:
settings = cls._ENV_SETTINGS
if key is None:
return settings
if isinstance(key, basestring):
key = [key]
value = settings
for k in key:
示例11: json_data
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def json_data(self):
return JSON.fromString(self._json_data) if self._json_data else None
示例12: snapshotData
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def snapshotData(self):
try:
out = JSON.fromString(self.snapshot)
return out if out is not None else dict()
except Exception:
return dict()
示例13: infoData
# 需要导入模块: from pyaid.json.JSON import JSON [as 别名]
# 或者: from pyaid.json.JSON.JSON import fromString [as 别名]
def infoData(self):
if self.info:
return JSON.fromString(self.info)
return dict()