save full JSON structure, how?

Just starting out? Need help? Post your questions and find answers here.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

save full JSON structure, how?

Post by minimy »

Hi, im trying to save a json file (utf8) with this code but not work, some body can help me. Thanks a lot.

Code: Select all

Structure lineasdechoquepuntos
  x.f
  y.f
EndStructure
Structure lineasdechoque
  List p1.lineasdechoquepuntos()
  List p2.lineasdechoquepuntos()
EndStructure
Global NewList lineas.lineasdechoque()

If CreateJSON(1)
   InsertJSONStructure(JSONValue(1), Lineas(), lineasdechoque)
   txt.s= ProcedureReturn ComposeJSON(1,#PB_JSON_PrettyPrint)
EndIf
lineas() have a lot of elements but only return in txt the first one.
like this:

Code: Select all

{
  "p1": [
      {
        "x": 3.9453125,
        "y": 4.859375
      }
    ],
  "p2": [
      {
        "x": 3.90625,
        "y": 4.0859375
      }
    ]
}
but if i use this, break and return invalid memory acces

Code: Select all

If CreateJSON(1)
   InsertJSONStructure(JSONValue(1), @Lineas, lineasdechoque)
   txt.s= ProcedureReturn ComposeJSON(1,#PB_JSON_PrettyPrint)
EndIf

What are doing bad?. Thanks again for help
If translation=Error: reply="Sorry, Im Spanish": Endif
cas
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Nov 03, 2008 9:56 pm

Re: save full JSON structure, how?

Post by cas »

User avatar
falsam
Enthusiast
Enthusiast
Posts: 630
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: save full JSON structure, how?

Post by falsam »

I'm surprised you got a result with code containing errors. :wink:

Code: Select all

InsertJSONStructure(JSONValue(1), Lineas(), lineasdechoque)
InsertJSONStructure() saves a structure. Not a list : lineas() is a list

:idea: InsertJSONList(JSONValue, List()) insert the specified List() into the given JSON value

Code: Select all

txt.s= ProcedureReturn ComposeJSON(1,#PB_JSON_PrettyPrint)
This code generates a compilation error.

If I understood your request correctly, the code should be this one.

Code: Select all

Structure lineasdechoquepuntos
  x.f
  y.f
EndStructure

Structure lineasdechoque
  List p1.lineasdechoquepuntos()
  List p2.lineasdechoquepuntos()
EndStructure

;You have created a List With your lineasdechoque Structure
Global NewList lineas.lineasdechoque()

;Insert the List  lineas() into the given JSON value
If CreateJSON(1)
   InsertJSONList(JSONValue(1), Lineas())
   Debug  ComposeJSON(1,#PB_JSON_PrettyPrint)
EndIf

➽ Windows 11 64-bit - PB 6.0 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 344
Joined: Mon Jul 08, 2013 8:43 pm

Re: save full JSON structure, how?

Post by minimy »

falsam wrote:I'm surprised you got a result with code containing errors. :wink:

Code: Select all

InsertJSONStructure(JSONValue(1), Lineas(), lineasdechoque)
InsertJSONStructure() saves a structure. Not a list : lineas() is a list

:idea: InsertJSONList(JSONValue, List()) insert the specified List() into the given JSON value

Code: Select all

txt.s= ProcedureReturn ComposeJSON(1,#PB_JSON_PrettyPrint)
This code generates a compilation error.

If I understood your request correctly, the code should be this one.

Code: Select all

Structure lineasdechoquepuntos
  x.f
  y.f
EndStructure

Structure lineasdechoque
  List p1.lineasdechoquepuntos()
  List p2.lineasdechoquepuntos()
EndStructure

;You have created a List With your lineasdechoque Structure
Global NewList lineas.lineasdechoque()

;Insert the List  lineas() into the given JSON value
If CreateJSON(1)
   InsertJSONList(JSONValue(1), Lineas())
   Debug  ComposeJSON(1,#PB_JSON_PrettyPrint)
EndIf
Many thanks to every body! PBforum the best! as allways!
Yeaaa! now work perfect!
I owe you three beers! :lol: :mrgreen:
If translation=Error: reply="Sorry, Im Spanish": Endif
Post Reply