var JSONObject: TJSONObject; JSONArray: TJSONArray; ... JSONObject:=TJSONObject.ParseJSONValue(S) as TJSONObject; try JSONArray := JSONObject.Get(0).JsonValue as TJSONArray; try Memo1.Lines.Add(JSONArray.Get(0).ToString); finally FreeAndNil(JSONArray); // если это закомментировать то работает но JSONArray остается в памяти. end; finally FreeAndNil(JSONObject); // а если нет, то тут вылетает Invalid pointer operation end; After the JSONObject destroyed, you can access the JSONArray (if we did not forcefully destroy it before) the object will exist, but the structure and data of the JSON document itself will not be there anymore. The same with JSONObject , if you first destroy JSONArray How, then, is it correct to destroy them and free memory?
Here is an example of a JSON document:
{"asks": [["0.01129999",0.9997237],["0.01130000",594.26412711],["0.01130826",0.23004724],["0.01130999",0.25231793]], "bids": [["0.01129800",174.30861783],["0.01128867",0.13287659],["0.01128817",0.0097447],["0.01127559",241.94881004]], "isFrozen":"0","seq":254407265 }
JSONObject. What structure are you trying to parse? - zedFreeAndNil(JSONArray)then the error Invalid pointer operation will not occur when you destroyJSONObject, BUT after this destruction you can refer toJSONArray, for example:Memo1.Lines.Add(JSONArray.ClassParent.ClassName);From what I conclude that the object remains. - HeathRowJSONArrayafter destroyingJSONObject. - zedJSONArraythat in factJSONArraynot destroyed whenJSONObjectdestroyed, as I was written above. - HeathRow