Tx, I tried Your proposal.�� Just as an example, it works:
(ZnClient new
�� url: 'http://api.wunderground.com/
�� contentReader: [ :entity |
��������(NeoJSONReader on: entity readStream)
�������������� mapClass: NeoJSONObject;
�������������� propertyNamesAsSymbols: true;
�������������� next ];
�� get ) hourly_forecast collect: [:e | e FCTTIME hour_padded asInteger ]
��
P.S.: Editor in Playground shows NeoJSONObject keys in red color?
If you are using NeoJSON you might want to take a look at the NeoJSONObject class. It's basically a Dictionary with "JavaScript" behavior.
I.e. you can simply use messages to access keys and non existing keys return nil. Your example can thus be written as:
val := dict1 key1 key2 key3.
When using NeoJSON you can simply configure your Mapper (Reader/Writer) to use NeoJSONObject using #mapClass:
CU,
Udo
On 24/04/2017 20:04, Markus B��hm wrote:
Tx for advice.
P.S.: I got nested dictionaries after JSON API call at wunderground weather API. To see all the response in Pharo inspector "live" is really great :-)
BR Mike
On Mon, Apr 24, 2017 at 7:51 PM, Cyril Ferlicot D. <cyril.ferlicot@gmail.com <mailto:cyril.ferlicot@gmail.com >> wrote:
�� �� Le 24/04/2017 �� 19:42, Markus B��hm a ��crit :
�� �� ��> May I ask:
�� �� ��> What's the idiomatic way to retrieve values from nested dictionaries?
�� �� ��>
�� �� ��> (((dict1 at: 'key1') at: 'key2') at: 'key3')
�� �� ��>
�� �� ��> Are all the brackets really necessary?
�� �� ��>
�� �� ��> BR Mike
�� �� Hi,
�� �� To know if brackets are necessary you can use the "Format" option in
�� �� your method.
�� �� Right click -> format
�� �� or cmd/alt/ctrl + shift + f
�� �� In this case you can just write:
�� �� ((dict1 at: 'key1') at: 'key2') at: 'key3'.
�� �� --
�� �� Cyril Ferlicot
�� �� https://ferlicot.fr
�� �� http://www.synectique.eu
�� �� 2 rue Jacques Pr��vert 01,
�� �� 59650 Villeneuve d'ascq France