Page 1 of 1

ExtractJSONStructure() and list not initialized

Posted: Wed May 04, 2016 9:49 pm
by Olby
Hi,

Recently I've been using JSON library pretty extensively and never had an issue with it until today when it stopped extracting a particular layout. Perhaps there is something I overlooked (hopefully) but I just can't seem to understand why foo\bar\a\a2() list is empty and in in fact is not initialized after ExtractJSONStructure call. Any ideas? Thanks.

Code: Select all

EnableExplicit

Define json$="{"+Chr(34)+"a"+Chr(34)+":{"+Chr(34)+"a1"+Chr(34)+":1901,"+Chr(34)+"a2"+Chr(34)+":[{"+Chr(34)+"aa1"+Chr(34)+":128,"+Chr(34)+"aa2"+Chr(34)+":"+Chr(34)+"Test1"+Chr(34)+"},{"+Chr(34)+"aa1"+Chr(34)+":129,"+Chr(34)+"aa2"+Chr(34)+":"+Chr(34)+"Test2"+Chr(34)+"}]},"+Chr(34)+"b"+Chr(34)+":[{"+Chr(34)+"bb1"+Chr(34)+":"+Chr(34)+"abc"+Chr(34)+","+Chr(34)+"bb2"+Chr(34)+":123,"+Chr(34)+"bb3"+Chr(34)+":{"+Chr(34)+"bb31"+Chr(34)+":"+Chr(34)+"TIF"+Chr(34)+","+Chr(34)+"bb32"+Chr(34)+":10000}},{"+Chr(34)+"bb1"+Chr(34)+":"+Chr(34)+"def"+Chr(34)+","+Chr(34)+"bb2"+Chr(34)+":321,"+Chr(34)+"bb3"+Chr(34)+":{"+Chr(34)+"bb31"+Chr(34)+":"+Chr(34)+"TIF"+Chr(34)+","+Chr(34)+"bb32"+Chr(34)+":10000}}],"+Chr(34)+"c"+Chr(34)+":{"+Chr(34)+"c1"+Chr(34)+":1999}}"

Structure Json_3
  aa1.i
  aa2$
EndStructure

Structure Json_2
  a1.i
  List a2.Json_3()
EndStructure

Structure Json_5
  bb31$
  bb32.i
EndStructure

Structure Json_4
  bb1$
  bb2.i
  bb3.Json_5
EndStructure

Structure Json_6
  c1.i
EndStructure

Structure Json_1
  a.Json_2
  List b.Json_4()
  c.Json_6
EndStructure

Structure Json
  parent.Json_1
EndStructure

Global foo.Json

ClearStructure(@foo,Json)
InitializeStructure(@foo,Json)
Debug ListIndex(foo\parent\a\a2())

If ParseJSON(0,json$)
	ExtractJSONStructure(JSONValue(0),@foo\parent,Json_1)
	FreeJSON(0)
	Debug ListIndex(foo\parent\a\a2())
	
EndIf
After JSON structure extraction ListIndex(foo\bar\a\a2()) will crash since the list has been free'd by JSON lib.

Re: ExtractJSONStructure() and list not initialized

Posted: Wed May 04, 2016 10:39 pm
by Olby
Nvm. Answered my own question: InitializeStructure does not work with nested structures and I have to call it for each level. Therefore the list was not initialized.