Page 1 of 1

ParseJSON fail when CreateJSON with #PB_Any

Posted: Wed Jul 03, 2019 7:37 pm
by benmalartre
hello,

Code: Select all

Define json.i = CreateJSON(#PB_Any)
Define datas$ = "[1, 2, 3, 4, 5]"  
ParseJSON(json, datas$)
give me this error:
[ERROR]#JSON object number is very high (over 10000), are you sure of that?

and stop the compilation

Re: ParseJSON fail when CreateJSON with #PB_Any

Posted: Wed Jul 03, 2019 8:34 pm
by kenmo
Hello! Maybe the documentation should be more clear about this:

You shouldn't CreateJSON() and then pass that ID into ParseJSON()... ParseJSON() automatically creates a new JSON.

Code: Select all

Define datas$ = "[1, 2, 3, 4, 5]" 
Define json.i = ParseJSON(#PB_Any, datas$)

You might already know this stuff:

This is how most PB objects work: You either create it with an index (a literal number like 0, or a constant, or a variable, etc.) OR you use the special value #PB_Any which dynamically creates a (high-value) ID.

If you pass in an index, say 10, PB allocates JSONs 0-10 for fast indexing.

That's why it warns you, if you generate a high-value #PB_Any ID (say... 500,000) then pass that ID in again, you're going to allocate JSONs 0-500,000 in memory... you probably don't want to do that!

Re: ParseJSON fail when CreateJSON with #PB_Any

Posted: Thu Jul 04, 2019 10:37 am
by benmalartre
It's not a compilation warning, it's a compilation error!!

But for sure I misread the documentation!!!
Sorry for the noise and thanks kenmo!

Ben

Re: ParseJSON fail when CreateJSON with #PB_Any

Posted: Thu Jul 04, 2019 10:49 am
by #NULL
benmalartre wrote:It's not a compilation warning, it's a compilation error!!
Neither. It's actually a runtime error. Disable the debugger and you won't get an error.

Re: ParseJSON fail when CreateJSON with #PB_Any

Posted: Mon Oct 21, 2019 8:10 am
by #NULL
rzoo1 wrote:I also face this issue. I've tried Kenmo's guide, but it can't work well
What's the problem? You just shouldn't reuse a dynamic ID generated with #PB_ANY as a static one. And you don't need to create a JSON object before ParseJSON.

(question was deleted while I answered)