@@ -50,7 +50,7 @@ NeoJSONObject class >> fromString: string [
50
50
" Parse string as JSON, so that maps become instances of me"
51
51
52
52
^ (NeoJSONReader on: string readStream)
53
- mapClass: NeoJSONObject ;
53
+ mapClass: self ;
54
54
propertyNamesAsSymbols: true ;
55
55
next
56
56
]
@@ -59,10 +59,25 @@ NeoJSONObject class >> fromString: string [
59
59
NeoJSONObject >> at: key [
60
60
" I return nil for missing keys.
61
61
My superclass would signal a KeyNotFound."
62
-
62
+
63
63
^ self at: key ifAbsent: [ nil ]
64
64
]
65
65
66
+ { #category : #' nested dictionaries' }
67
+ NeoJSONObject >> at: firstKey at: secondKey [
68
+ " I return nil for missing keys.
69
+ My superclass would signal a KeyNotFound."
70
+
71
+ ^ self atPath: { firstKey. secondKey }
72
+ ]
73
+
74
+ { #category : #' nested dictionaries' }
75
+ NeoJSONObject >> at: firstKey at: secondKey put: value [
76
+ " Store value under secondKey in nested object under firstKey, create new level when needed"
77
+
78
+ ^ self atPath: { firstKey. secondKey } put: value
79
+ ]
80
+
66
81
{ #category : #accessing }
67
82
NeoJSONObject >> at: key ifPresent: aPresentBlock ifAbsentPut: anAbsentBlock [
68
83
" Lookup the given key in the receiver. If it is present, answer the
@@ -71,7 +86,7 @@ NeoJSONObject >> at: key ifPresent: aPresentBlock ifAbsentPut: anAbsentBlock [
71
86
72
87
" Overwritten to patch a bug in the superclass implementation in Pharo 7 and 8.
73
88
This problem was fixed in Pharo 9 where this overwrite is no longer necessary but harmless."
74
-
89
+
75
90
^ self
76
91
at: key
77
92
ifPresent: aPresentBlock
@@ -81,19 +96,19 @@ NeoJSONObject >> at: key ifPresent: aPresentBlock ifAbsentPut: anAbsentBlock [
81
96
{ #category : #accessing }
82
97
NeoJSONObject >> atPath: keyCollection [
83
98
" Use each key in keyCollection recursively, stop when nil is encountered"
84
-
99
+
85
100
| value |
86
101
value := self .
87
102
keyCollection do: [ :each |
88
103
value := value at: each.
89
104
value ifNil: [ ^ nil ] ].
90
- ^ value
105
+ ^ value
91
106
]
92
107
93
108
{ #category : #accessing }
94
109
NeoJSONObject >> atPath: keyCollection put: newValue [
95
110
" Use each key in keyCollection recursively, create new levels when needed"
96
-
111
+
97
112
| target |
98
113
keyCollection ifEmpty: [ ^ self ].
99
114
target := self .
@@ -108,7 +123,7 @@ NeoJSONObject >> atPath: keyCollection put: newValue [
108
123
NeoJSONObject >> doesNotUnderstand: message [
109
124
" Overwritten so that 'self foo' becomes 'self at: #foo'
110
125
and 'self foo: 1' becomes 'self at: #foo put: 1' except that self is returned"
111
-
126
+
112
127
| key |
113
128
key := message selector.
114
129
key isUnary
@@ -121,7 +136,7 @@ NeoJSONObject >> doesNotUnderstand: message [
121
136
{ #category : #accessing }
122
137
NeoJSONObject >> name [
123
138
" Overwritten to make this accessor available as key"
124
-
139
+
125
140
^ self at: #name
126
141
]
127
142
@@ -131,15 +146,15 @@ NeoJSONObject >> printOn: stream [
131
146
132
147
[ (NeoJSONWriter on: stream) nextPut: self ]
133
148
on: Error
134
- do: [ :exception |
149
+ do: [ :exception |
135
150
stream
136
151
nextPutAll: ' Error printing JSON: ' ;
137
- nextPutAll : exception printString ]
152
+ print : exception ]
138
153
]
139
154
140
155
{ #category : #evaluating }
141
156
NeoJSONObject >> value [
142
157
" Overwritten to make this accessor available as key"
143
-
158
+
144
159
^ self at: #value
145
160
]
0 commit comments