Swift,如何从Pandas JSON fi导入JSON文件

2024-09-29 19:29:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我从Pandas导出了JSON文件, 我想从Swift/iOS导入JSON文件。在

编码协议的结构是正确的。在

我试图使用SWIFTYJSON,但也发生了同样的错误。在

这是熊猫守则。在

shops.to_json("sample.json", orient='records', force_ascii=False, lines=True)

我写的代码是这样的

^{pr2}$

错误如下

dataCorrupted(Swift.DecodingError.Context(codingPath: [], debugDescription: "The given data was not valid JSON.", underlyingError: Optional(Error Domain=NSCocoaErrorDomain Code=3840 "Garbage at end." UserInfo={NSDebugDescription=Garbage at end.})))

这是JSON示例

{"address":"港区赤坂1-11-6 赤坂テラスハウス 1階","category":"割烹・小料理","holiday":"日曜、祝日(詳細は公式HPのカレンダーに記載)","hours":"12:00~15:00(L.O.13:00)(木・土のみ営業)18:00~22:00(L.O.20:00)","latitude":35.6642294444,"longitude":139.7455658333,"moyori":"六本木一丁目","name":"sample restaurant2","pref":"東京都","price":"¥30,000~","rate":"4.88","url":"http://www.sample1.com","tel":"03-0000-0000","transportation":"東京メトロ 銀座線・南北線「溜池山王駅」13出口より、徒歩10分東京メトロ 南北線「六本木一丁目駅」3出口より、徒歩10分東京メトロ 日比谷線「神谷町駅」4b出口より、徒歩10分\n六本木一丁目駅から411m","website":"http://www.sample1.com","zip":"1070052"}
{"address":"港区六本木1-4-5 アークヒルズサウスタワー 1F","category":"寿司","holiday":"日曜・祝日(但し、連休にならない祝日は除く)","hours":"12:00~14:0017:00~23:00","latitude":35.6621280556,"longitude":139.7426308333,"moyori":"溜池山王","name":"sample restarurant2","pref":"東京都","price":"¥20,000~¥29,999","rate":"4.86","url":"http://www.sample.com","tel":"03-3589-4412","transportation":"溜池山王駅徒歩5分虎ノ門駅徒歩8分\n六本木一丁目駅から60m","website":"","zip":"1060032"}

我也测试过这个jsonfile

   [{"address":"港区赤坂1-11-6 赤坂テラスハウス 1階","category":"割烹・小料理","holiday":"日曜、祝日(詳細は公式HPのカレンダーに記載)","hours":"12:00~15:00(L.O.13:00)(木・土のみ営業)18:00~22:00(L.O.20:00)","latitude":35.6642294444,"longitude":139.7455658333,"moyori":"六本木一丁目","name":"sample restaurant2","pref":"東京都","price":"¥30,000~","rate":"4.88","url":"http://www.sample1.com","tel":"03-0000-0000","transportation":"東京メトロ 銀座線・南北線「溜池山王駅」13出口より、徒歩10分東京メトロ 南北線「六本木一丁目駅」3出口より、徒歩10分東京メトロ 日比谷線「神谷町駅」4b出口より、徒歩10分\n六本木一丁目駅から411m","website":"http://www.sample1.com","zip":"1070052"},{"address":"港区六本木1-4-5 アークヒルズサウスタワー 1F","category":"寿司","holiday":"日曜・祝日(但し、連休にならない祝日は除く)","hours":"12:00~14:0017:00~23:00","latitude":35.6621280556,"longitude":139.7426308333,"moyori":"溜池山王","name":"sample restarurant2","pref":"東京都","price":"¥20,000~¥29,999","rate":"4.86","url":"http://www.sample.com","tel":"03-3589-4412","transportation":"溜池山王駅徒歩5分虎ノ門駅徒歩8分\n六本木一丁目駅から60m","website":"","zip":"1060032"}]

错误是这样的

typeMismatch(Swift.Dictionary<Swift.String, Any>, Swift.DecodingError.Context(codingPath: [], debugDescription: "Expected to decode Dictionary<String, Any> but found an array instead.", underlyingError: nil))
enter code here

Tags: samplenamecomjsonhttpaddresswwwswift

热门问题