VBA-tools / VBA-JSON

JSON conversion and parsing for VBA
MIT License
1.76k stars 568 forks source link

ParseJson fails if array is empty #158

Open pauloneill opened 4 years ago

pauloneill commented 4 years ago

I've copied your JSON library into my Word project to manage some simple licensing requirements and it mostly works.

The problem I do have is that ParseJson fails to correctly parse this:

{"result":"success","message":"License key details retrieved.","license_key":"abc123","status":"active","max_allowed_domains":"1","email":"test@test.com","registered_domains":[],"date_created":"0000-00-00","date_renewed":"2020-01-08","date_expiry":"2021-01-08","product_ref":"Test Product","first_name":"John","last_name":"Smith","company_name":"","txn_id":"1","subscr_id":""}

For me, it fails in json_ParseObject on the line:

returnDictionary(json_Key) = json_ParseValue(json_String, json_Index)

where json_Index = 193 - which appears to be after the registered_domains entry.

Hopefully, you can reproduce this and then advise how to fix it.

TIA Paul

pauloneill commented 4 years ago

UPDATE: I got the exact same code working in Excel so is this a conflict between Word.Dictionary and Scripting.Dictionary, and is there an easy workaround?

Thanks Paul

pauloneill commented 4 years ago

Final update: I was using both VBA-Web and VBA-JSON (and VBA-test) all together in Word and now have a working solution that checks my licencing from Word VBA.

Let me know if you'd like my changes so you can incorporate them into a Word version. It'll be tricky as you've simply used Dictionary to make it Mac compatible whereas Scripting.Dictionary will make it Windows compatible and will require a separate Mac version...

Hope this is useful Paul

houghtonap commented 4 years ago

FYI, VBA supports conditional interpretation. For example:

if Win then

Dim obj as Scripting.Dictionary

Elseif Mac

Dim obj as Dictionary

Else

Dim obj as Object

EndIf

One can also test if an object exists, I forget the syntax, for example.

If obj is Nothing Set obj = createobject("Scripting.Dictionary") End if

If obj is Nothing then Set obj = createobject("Dictionary") End if

If obj = Nothing then ' Error End if

Get Outlook for Android


From: pauloneill notifications@github.com Sent: Wednesday, January 8, 2020 9:57:42 PM To: VBA-tools/VBA-JSON VBA-JSON@noreply.github.com Cc: Subscribed subscribed@noreply.github.com Subject: Re: [VBA-tools/VBA-JSON] ParseJson fails if array is empty (#158)

Final update: I was using both VBA-Web and VBA-JSON (and VBA-test) all together in Word and now have a working solution that checks my licencing from Word VBA.

Let me know if you'd like my changes so you can incorporate them into a Word version. It'll be tricky as you've simply used Dictionary to make it Mac compatible whereas Scripting.Dictionary will make it Windows compatible and will require a separate Mac version...

Hope this is useful Paul

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/VBA-tools/VBA-JSON/issues/158?email_source=notifications&email_token=AIKTRAY3GDKC4OEONI7BTQTQ42HCNA5CNFSM4KEEK722YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEIOYILI#issuecomment-572359725, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AIKTRA3UHGXTPYCBJGNIY3TQ42HCNANCNFSM4KEEK72Q.

pauloneill commented 4 years ago

Hi Andrew

Yes, I was aware of that but I hadn't forked the project so was simply offering my changes back to Tim incase he wanted to add Windows/Word functionality...

Cheers Paul