I just want to ask something about json and python.
我只是想问一些关于json和python的东西。
If I'm correct, loading a StringIO to json would result to it having a u'
.
如果我是正确的,将StringIO加载到json将导致它具有u'。
for example, in the json library:
例如,在json库中:
>>> from StringIO import StringIO
>>> io = StringIO('["streaming API"]')
>>> json.load(io)
results to
结果
[u'streaming API']
so how do I parse this data? in order for me to sort a data that looks like this? I have this data I want to parse.
那么我该如何解析这些数据呢?为了让我对这样的数据进行排序?我有这个想要解析的数据。
{u'brix': {u'Nov 29, 2017 11:20:15 PM': {u'Checklist': {u'Coffee tray with 3 coffee sticks, 3 creamer, 3 white sugar, 3 brown sugar, 1 equal or sweetener, 3 lipton tea, 2 mineral water, 3 cocktail napkin ?': u'No', u'Luggage bench fabric top is clean': u'No', u'1 facial tissue in a tissue box': u'No', u'Towel Reminder': u'No', u'1 pringles, 1 cashew nut, 1 cup noodles (placed in the coffee tray on the writing desk)?': u'No',
{u'brix':{u'Nov 29,2017 11:20:15 PM':{u'Checklist':{u'Coffee托盘配3根咖啡棒,3个奶精,3个白糖,3个红糖,1个相等或者是甜味剂,3个里顿顿茶,2个矿泉水,3个鸡尾酒餐巾?':你不',你的行李凳面料上面很干净':你不',你在纸巾盒里的面巾纸':你'没有',''''''''''''''''''''''''''1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1''''''''''''''''''''''''''''''''''''''''
After reading a bit about json I found out that this may be a StringIO instead of a json. It was silly that I tried to do json.loads with it when I it's already loaded. All I want is to sort all of these data so it appears properly on web.
在阅读了一些关于json之后,我发现这可能是一个StringIO而不是一个json。当我已经加载时,我试图用它做json.loads是愚蠢的。我想要的是对所有这些数据进行排序,使其在网络上正确显示。
How do i properly do this? Do i decode these to json first so it becomes something like
我该如何正确地做到这一点?我首先将这些解码为json所以它变成了类似的东西
{
"maps":[
{"id":"blabla","iscategorical":"0"},
{"id":"blabla","iscategorical":"0"}
],
"masks":
{"id":"valore"},
"om_points":"value",
"parameters":
{"id":"valore"}
}
Then get a value from that using this?
然后从中获取一个值?
data["maps"][0]["id"] # will return 'blabla'
data["masks"]["id"] # will return 'valore'
data["om_points"] # will return 'value'
Anyway, I'm confused of what I should do, I tried pretty much everything, these example came from other questions .
无论如何,我对我应该做的事情感到困惑,我几乎尝试了一切,这些例子来自其他问题。
Here's a bit of my code:
这是我的一些代码:
result1 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-in/Inspector/', None)
result2 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-out/Inspector/', None)
print result1["brix"]
Firebase is supposed to return a json file. lol but it doesn't work on mine.
Firebase应该返回一个json文件。大声笑,但它不适用于我的。
Thankyou very much to those who will clear it out to me.
非常感谢那些愿意向我透露的人。
1 个解决方案
#1
0
you are receiving a Unicode json just as the comment says, if you want the output there's no need to convert to normal function. You can simply do something like this:
您正在接收Unicode json,就像评论所说,如果您想要输出,则无需转换为正常功能。你可以简单地做这样的事情:
result1 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-in/Inspector/', None)
result2 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-out/Inspector/', None)
result1 = result1["brix"]["Nov 29, 2017 11:20:15 PM"]["Checklist"]["Luggage bench fabric top is clean"]
You will be receiving the
你将收到
No
没有
string, without the 'u
字符串,没有'你
Here's the reference: https://docs.python.org/2/library/json.html
以下是参考:https://docs.python.org/2/library/json.html
Look at the Decoding JSON part, there's the StringIO import, refer there for more information if you haven't read it yet.
查看解码JSON部分,有StringIO导入,如果您尚未阅读,请参阅那里以获取更多信息。
#1
0
you are receiving a Unicode json just as the comment says, if you want the output there's no need to convert to normal function. You can simply do something like this:
您正在接收Unicode json,就像评论所说,如果您想要输出,则无需转换为正常功能。你可以简单地做这样的事情:
result1 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-in/Inspector/', None)
result2 = firebase.get('/Rooms/Room1/2017-11-29/Inspection/Scan-out/Inspector/', None)
result1 = result1["brix"]["Nov 29, 2017 11:20:15 PM"]["Checklist"]["Luggage bench fabric top is clean"]
You will be receiving the
你将收到
No
没有
string, without the 'u
字符串,没有'你
Here's the reference: https://docs.python.org/2/library/json.html
以下是参考:https://docs.python.org/2/library/json.html
Look at the Decoding JSON part, there's the StringIO import, refer there for more information if you haven't read it yet.
查看解码JSON部分,有StringIO导入,如果您尚未阅读,请参阅那里以获取更多信息。