如何用python解析未序列化的json
我有一个来自core NLP的JSON响应,如下所示:如何用python解析未序列化的json,python,json,stanford-nlp,Python,Json,Stanford Nlp,我有一个来自core NLP的JSON响应,如下所示: text: "Tell me what the notes are for South Australia " sentence { token { word: "Tell" pos: "VB" value: "Tell" before: "" after: " " originalText: "Tell" } token { word: "me" pos: "PR
text: "Tell me what the notes are for South Australia "
sentence {
token {
word: "Tell"
pos: "VB"
value: "Tell"
before: ""
after: " "
originalText: "Tell"
}
token {
word: "me"
pos: "PRP"
value: "me"
before: " "
after: " "
originalText: "me"
}
tokenOffsetBegin: 0
tokenOffsetEnd: 9
basicDependencies {
node {
sentenceIndex: 0
index: 1
}
}
....
question {
text: "Tell me what the notes are for South Australia "
sentence {
....
}
重要的部分是循环遍历标记,并获取例如单词、位置、值和。。。。对于每个令牌。
此代码:
for s in client.annotate("Tell me what the notes are for South Australia"):
for t in s:
words.append(t.word)
gloss.append(t.originalText)
after.append(t.after)
不起作用,它说我不能迭代到JSON输出中,因为它的类型不同,我能做什么?它不是JSON。这是显而易见的,因为:
text: "Tell me what the notes are for South Australia "
sentence {
....
如果确实是,这将抛出一个错误。像这样修复它:
text: "Tell me what the notes are for South Australia "
sentence {
token {
word: "Tell"
pos: "VB"
value: "Tell"
before: ""
after: " "
originalText: "Tell"
}
token {
word: "me"
pos: "PRP"
value: "me"
before: " "
after: " "
originalText: "me"
}
tokenOffsetBegin: 0
tokenOffsetEnd: 9
basicDependencies {
node {
sentenceIndex: 0
index: 1
}
}
....
question {
text: "Tell me what the notes are for South Australia "
sentence {
....
}
或者别的什么。无论如何,这不是JSON。那不是JSON。我打赌
pycorenelp
有一个解析器。我知道它不是JSON,但它说它返回JSON我该怎么做?我修复的不是一个数据,服务器生成这个数据只是更改jquery的添加。