简体   繁体   English

茉莉花无法读取有效的json文件

[英]Jasmine can't read a valid json file

I have this JSON file : 我有这个JSON文件:

{
"Address": [{
    "street": "rue de la paix",
    "zipcode": "3049"
}, {
    "street": "champs de mars",
    "zipcode": "2303"
}]
}

Which is valid. 哪个有效 I'm trying to read that file in one of my Jasmine specifications. 我正在尝试以我的Jasmine规范之一读取该文件。 When I ajax it I get my file contents and everything works fine. 当我执行ajax时,我得到了文件内容,并且一切正常。

But, when I launch my test maven in console log I get error Uncaught SyntaxError: Unexpected token : in the second line, just after the "Address". 但是,当我启动我的测试maven在控制台日志中我得到错误未捕获的SyntaxError:意外的标记:在第二行中,只是在“地址”。 在此处输入图片说明

And if I remove the ":" the error disappears but I can no longer read the file (which is very understandable). 而且,如果我删除“:”,错误消失了,但我无法再读取文件(这是很容易理解的)。

Code of maven goal is defined as follows: Maven目标代码定义如下:

<plugin>
   <groupId>com.github.searls</groupId>
   <artifactId>jasmine-maven-plugin</artifactId>
   <version>2.0</version>
   <executions>
      <execution>
         <goals>
            <goal>test</goal>
         </goals>
      </execution>
   </executions>
   <configuration>
      <specRunnerTemplate>REQUIRE_JS</specRunnerTemplate>
      <preloadSources>
         <source>jsonResources/testjson.json</source>
      </preloadSources>
      <specIncludes>
         <include>**/*.spec.js</include>
      </specIncludes>
   </configuration>
</plugin>

Had anyone had a similar problem ? 有人遇到过类似的问题吗?

Obviously maven doesn't like json file referenced as source. 显然, maven不喜欢作为源引用的json文件。 Because it is parsed as javascript code 因为它被解析为javascript代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM