-3
A
回答
0
你必须给路径的文件类型为JSON 作为
guard let jsonpath = bundle.main.path(forResource: "MainVCString", ofType: "json"),
+0
不,它不能解决我的问题。jasonURL hava值。 –
0
这个怎么样?
if let fileURL = Bundle.main.url(forResource: "MainVCString", withExtension: "json"){
if let data = try? Data(contentsOf: fileURL, options: Data.ReadingOptions.uncached){
print("This works!")
}else{
print("Something wrong with the path.")
}
}
相关问题
- 1. 无法获取令牌youtube-data-api
- 2. 无法获取值
- 3. 如何获取data-id值
- 4. GAIDictionaryBuilder无法获取NSNumber值
- 5. 无法获取会话值
- 6. 无法从sharedpreferences获取值
- 7. WP7:无法获取Canvas.RenderTransform值
- 8. 无法获取UIAStaticText的值?
- 9. 无法获取宏的值
- 10. 无法获取属性值
- 11. SwiftyJSON:无法获取值
- 12. getJSON无法获取子值
- 13. JComboBox - 无法获取值
- 14. 无法获取cookie值
- 15. 无法获取NSSingleEntryDictionary的值
- 16. C#--DataGridView - 无法获取ColumnCount,无法获取单元格值
- 17. 使用Spring Data获取单个NonNull值
- 18. Ember-data - 获取模型的哈希值
- 19. Struts2:无法从值堆栈获取值
- 20. 为什么我无法获取自动填充输入字段的data()值?
- 21. 无法获取DOM节点值提取
- 22. 无法从远程方法获取值
- 23. 无法从GET方法获取价值
- 24. 使用Spring Data REST无法捕获DataIntegrityViolationException
- 25. jquery无法更新data-num值
- 26. 无法用Core Data更新值
- 27. jQuery无法获得data- *属性值,返回undefined
- 28. Holder.js和Bootstrap卡 - 无法获取img data-src显示
- 29. CodeIgniter 2.1.3 - 表单助手 - 无法获取DATA提交
- 30. Ember Data:无法从数据存储中获取模型
的我的代码是一个图片 –
为什么不使用相关的API'后卫的URL让jsonURL = Bundle.main.url(forResource: “MainVCString”,withExtension: “JSON”)'?这避免了第二个“警卫”。并使用'do-catch'而不是'try?'来获取错误信息。 – vadian
'URL(string:jsonPath)'应该是'URL(fileURLWithPath:jsonPath)' - 但是最好在@vadian建议的地方首先使用URL。 –