我正在尝试使用机器人框架和Httplibrary解析json文件,但在解析时我遇到了问题。请在下面输出部分了解更多详情,请告诉我可能的解决方案。
输入文件以读取sample.json
{
"age":100,
"name":"mkyong.com",
"messages":["msg 1","msg 2","msg 3"]
}
机器人框架代码
*** Settings ***
Documentation Test our very first REST API
Library HttpLibrary.HTTP
Library OperatingSystem
*** Test Cases ***
Create Question Should Return Success
Created Question Details Should Be Correct
*** Keywords ***
Created Question Details Should Be Correct
${expectation} = Parse Json From File
Log ${expectation}
Parse Json From File
${file} = Get File sample.json
${json} = Parse Json ${file}
[Return] ${json}
但解析json文件后得到以下输出:
{
u'age':100,
u'name':u'mkyong.com',
u'messages':[u'msg 1',u'msg 2',u'msg 3']
}
答案 0 :(得分:0)
Parse Json
关键字应该返回一个数据结构,这意味着它的行为完全正确。
尝试检索您的一些值:
Parse Json From File
${file} = Get File sample.json
${json} = Parse Json ${file}
Log Get Json Value ${json} /age
Log Get Json Value ${json} /name
Log Get Json Value ${json} /messages
[Return] ${json}