2016-10-20 39 views
0

我無法使用json.load()加載我的json文件。我的格式是geojson用下面的例子格式:geoJson:Json.load()ValueError:預計屬性名稱:第2行第9列

{ "type" : "Feature Collection", 
     {"features" : [ 
      { "type" : "Feature", 
     "id" : "FORT_1", 
      "geometry" : { 
       "type" : "Point", 
       "coordinates" : ["121.046859", "14.54544278"]}, 
     "properties" : { "name" : "City"} 
     }, 
      { "type" : "Feature", 
     "id" : "FORT_2", 
      "geometry" : { 
       "type" : "Point", 
       "coordinates" : ["121.0500991", "14.54973692"]}, 
     "properties" : { "name" : "One"} 
     }, 

我想測試一下使用下面的代碼,因爲他們知道這將創建一個dict

  with open(geojsonFilePath) as file: 
      jsonFile = json.load(file) 

      for feature in jsonFile['features']: 
       print (['id']) 
       print (['geometry'],['type']) 
       print (['geometry'],['coordinates']) 
       print (['properties'],['name']) 

但是在出現錯誤線jsonFile = json.load(file)

+0

什麼是「FORT_1」和「FORT_2」?你的json對那些無效 –

+0

@MosesKoledoye hangon讓我檢查我的模板並重試。儘管錯誤指出了@ {「features」:{放置的位置。 – Reiion

+0

@MosesKoledoye無論如何我重新檢查它有相同的錯誤 – Reiion

回答

0

這裏都是您的JSON的問題,我能找到

首先,在

{ "type" : "Feature Collection", 
    {"features" : [ 

你沒有鑰匙添加一個對象,它應該是

{ "type" : "Feature Collection", 
    "features" : [ 

{ "type" : "Feature Collection", 
    "somekey": features" : [ 

然後,是FORT_1FORT_2,這看起來好像是變量名或常數,所以這應該用引號括起來,或者這些變量/常數的值需要被替換。

最後,有很多不匹配的大括號,不知道您是否共享了一個片段或整個json,但功能的數組大括號未關閉,後續大括號未關閉。

我已經更正了您的輸入,並提供了一些供參考的假設。

{ 
    "type": "Feature Collection", 

    "features": [{ 
     "type": "Feature", 
     "id": "FORT_1", 
     "geometry": { 
      "type": "Point", 
      "coordinates": ["121.046859", "14.54544278"] 
     }, 
     "properties": { 
      "name": "City" 
     } 
    }, { 
     "type": "Feature", 
     "id": "FORT_2", 
     "geometry": { 
      "type": "Point", 
      "coordinates": ["121.0500991", "14.54973692"] 
     }, 
     "properties": { 
      "name": "One" 
     } 
    }] 

} 
+0

你好先生謝謝你清楚地指出我的錯誤在那一行。我解決了它,現在只是有一個分隔符錯誤。 :) 謝謝! – Reiion

+0

我想問一下,如果我的json說可能是這樣結束的話,它仍然有效:'「id:」FORT_2「, 」geometry「:{ 」類型 「: 」點「, 」座標「:[」 121.0500991" , 「14.54973692」] }, 「屬性」:{ 「姓名」: 「一」 } },] }' – Reiion

+0

其中逗號仍然出現在第二個符號之前?這只是因爲我現在正在使用模板,修復此錯誤後出現分隔符問題。我想知道這是否是原因? – Reiion

相關問題