Arrays 字符串中的jsonarray返回为null
将字符串转换为JSONArray的这一行代码片段返回为null,有什么想法吗Arrays 字符串中的jsonarray返回为null,arrays,json,kotlin,Arrays,Json,Kotlin,将字符串转换为JSONArray的这一行代码片段返回为null,有什么想法吗 JSONArray("""[{"id":1,"first":"John","last":"Doe"}]""") 这是我的依赖项 dependencies { implementation fileTree(dir: 'libs', include:
JSONArray("""[{"id":1,"first":"John","last":"Doe"}]""")
这是我的依赖项
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.4'
implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
implementation "androidx.navigation:navigation-ui-ktx:$nav_version"
implementation "androidx.navigation:navigation-dynamic-features-fragment:$nav_version"
androidTestImplementation "androidx.navigation:navigation-testing:$nav_version"
testImplementation 'junit:junit:4.13'
testImplementation 'org.mockito:mockito-inline:2.13.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
implementation 'androidx.test.espresso:espresso-idling-resource:3.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.2.0'
androidTestImplementation 'androidx.test:rules:1.3.0-alpha05'
implementation 'com.google.android.material:material:1.1.0'
}
后续问题。使用JUnit从SUT调用localhost
我假设您必须运行Android项目中模块/测试下的单元测试 如果您试图在JUnit测试中使用或访问与Android相关的代码,则除非您没有在模块的
build.gradle
文件中添加以下代码行,否则该代码将无法工作
testOptions {
unitTests.returnDefaultValues = true
unitTests.includeAndroidResources = true
}
一旦您添加了上述配置,对Android方法的任何访问都将返回其默认值,无论您传递给它们什么
任何与android测试相关的内容都需要在androidTest
更多信息
你是对的,这个类是一个SUT,正在测试中运行,但是,我仍然得到null,仍然在检查我是否一切都正确,有什么想法吗?请检查我的依赖关系,在我在
testImplementation'org.json:json:20140107'中添加了一些研究之后,
,但是,还有另一个问题,我正在通过localhost进行测试http://10.0.2.2:8080
(参见第二个屏幕截图),我也非常感谢您在这里的输入。感谢json错误的出现,我认为您的项目似乎无法获取依赖项。现在手动下载,然后尝试测试一次,如果这有助于您解决问题。请手动下载并将其用作依赖项,请参阅