这个斯文(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
我想你是对的;-) –