這個斯文(NeoJSON的作者)在菲羅用戶郵件列表的答案(他是不是在SO):
讀「格式」很簡單,只需繼續做#next每個JSON表達式(空格被忽略)。
| data reader |
data := '{"smalltalk": "cool"}
{"pharo": "cooler"}'.
reader := NeoJSONReader on: data readStream.
Array streamContents: [ :out |
[ reader atEnd ] whileFalse: [ out nextPut: reader next ] ].
防止中間數據結構也很容易,使用流媒體。
| client reader data networkStream |
(client := ZnClient new)
streaming: true;
url: 'https://github.com/NYPL-publicdomain/data-and-utilities/blob/master/items/pd_items_1.ndjson?raw=true';
get.
networkStream := ZnCharacterReadStream on: client contents.
reader := NeoJSONReader on: networkStream.
data := Array streamContents: [ :out |
[ reader atEnd ] whileFalse: [ out nextPut: reader next ] ].
client close.
data.
花了幾秒鐘的時間,畢竟50K的項目在網絡上是80MB +。
我想,你的意思是$ [和$]做一個數組?這很好。 – MartinW
我想你是對的;-) –