CSV到JSON整数解析错误使用占位符

n1bvdmb6  于 11个月前  发布在  其他
关注(0)|答案(2)|浏览(132)

所以我有一个CSV文件,从那里我正在解析JSON中的数据,但有整数转换问题。

  • def foo = '10'
  • string json = { bar:'#(1 * foo)' }
  • match json == '{“bar”:10.0}'
  • string json = { bar:'#(parseInt(foo))' }
  • match json == '{“bar”:10.0}'

所以我尝试了两种方法将字符串转换为整数,但我得到了下面的错误消息:“JSON解析错误:无法从字符串中解析java.lang.Integer类型的值“(1 * total_amount)":不是一个有效的java.lang.Integer值”。1000是我在CSV文件中给出的值。
4.0.0

<groupId>org.karateauto</groupId>
<artifactId>Karate-Lead_Demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <java.version>11</java.version>
    <maven.compiler.version>3.11.0</maven.compiler.version>
    <maven.surefire.version>3.0.0</maven.surefire.version>
    <karate.version>1.4.1</karate.version>
</properties>
<dependencies>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit5</artifactId>
        <version>${karate.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-core</artifactId>
        <version>${karate.version}</version>
        <classifier>all</classifier>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>RELEASE</version>
        <scope>test</scope>
    </dependency>
</dependencies>
<build>
    <testResources>
        <testResource>
            <directory>src/test/java</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </testResource>
    </testResources>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>${maven.compiler.version}</version>
            <configuration>
                <encoding>UTF-8</encoding>
                <source>${java.version}</source>
                <target>${java.version}</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>${maven.surefire.version}</version>
            <configuration>
                <argLine>-Dfile.encoding=UTF-8</argLine>
            </configuration>
        </plugin>
    </plugins>
</build>

上面是我的pom文件。
{“action”:“#(action)",“currency”:“#(currency)",“cptrid”:“#(cptrid)",“flex1”:“#(flex1)",“flex2”:“#(flex2)",“flex3”:“#(flex3)",“flex4”:“#(flex4)",“sys_id”:“#(sys_id)",“lead_id”:“#(lead_id)",“record_id”:“#(record_id)",“付款方式”:“#(mode_of_payment)",“total_amount”:“#(1 * total_amount)",“instrument_ref”:“#(instrument_ref)",“instrument_date”:“#(instrument_date)",“bank_name”:“#(bank_name)",“分支_detls”:“#(分支_detls)",“receipt_no”:“#(receipt_no)”}
上面是我使用占位符表示总金额的方式。

zf9nrax1

zf9nrax11#

Feature: Integer parsing feature

  Scenario Outline: Integer parsing scenario
    Given url 'https://reqres.in/api/users'
    And request {"name":'#(name)',"job":'#(parseInt(job))'}
    When method post
    Then status 201

    Examples: 
      | read('classpath:testdata/create_post_testdata.csv').slice(0, 2) |

字符串
csv文件:

name,job
Json-server1,1
Json-server2,2

3df52oht

3df52oht2#

我运行了下面的程序,它在空手道1.4.1中运行得很好。

* def foo = '10'
* string json = { bar: '#(1 * foo)' }
* match json == '{"bar":10}'
* string json = { bar: '#(parseInt(foo))' }
* match json == '{"bar":10}'

字符串
你还有别的事情要做,所以遵循这个过程:https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

相关问题