ParseJSON fail when CreateJSON with #PB_Any

Just starting out? Need help? Post your questions and find answers here.
benmalartre
User
User
Posts: 27
Joined: Thu Mar 14, 2013 11:24 am
Location: paris
Contact:

ParseJSON fail when CreateJSON with #PB_Any

Post 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
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: ParseJSON fail when CreateJSON with #PB_Any

Post 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!
benmalartre
User
User
Posts: 27
Joined: Thu Mar 14, 2013 11:24 am
Location: paris
Contact:

Re: ParseJSON fail when CreateJSON with #PB_Any

Post 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
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: ParseJSON fail when CreateJSON with #PB_Any

Post 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.
#NULL
Addict
Addict
Posts: 1440
Joined: Thu Aug 30, 2007 11:54 pm
Location: right here

Re: ParseJSON fail when CreateJSON with #PB_Any

Post 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)
Post Reply