【问题标题】:Getting issue while reading json file with robot framework使用机器人框架读取 json 文件时出现问题
【发布时间】:2017-11-11 03:41:18
【问题描述】:

我正在尝试使用机器人框架和 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']
}

【问题讨论】:

    标签: robotframework


    【解决方案1】:

    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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      • 1970-01-01
      • 2022-01-01
      • 2022-10-07
      • 1970-01-01
      相关资源
      最近更新 更多