#1 2018-01-31 16:07:06

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 37

JSON Parse problem

Version: 4885

This JSON text can't be parsed using RecordLoadJSON function and the reader reported false assigned to wasValid

    FirstChar := JSON^;
    JSON := Reader(JSON,Rec,wasValid);
    if not wasValid then
      exit;


  '{"Head":{"RECORD_AUTOINC":2,"RECORD_INDICATOR":3565564291285041560},"Account":"BA83283277F8999","BIC":"FNBOUS44","InstitutionAccount":"7770100000","FinancialAccount":"12345678901234567890","EncryptionKey":"CCCA01A25A7CF5A98109","Currency":840,"MultiCurrency":true,"CommonName":"MERCHANT.strong-data.COM","Subject":1994948748,"CASubject":1788932080,"Issuer":"Users CA","ProfileID":11}

Offline

#2 2018-01-31 16:34:08

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: JSON Parse problem

Please don't post in the forum huge pieces of code or JSON - as stated by the forum rules.

I don't know where your 4885 version number comes from. We currently are in version 1.18.4200.

You don't give enough information.
How is your record defined?

Offline

#3 2018-01-31 18:53:26

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 37

Re: JSON Parse problem

Hello,

4485 is from this repository https://github.com/synopse/mORMot.git/trunk

Please consider this record definition: https://mega.nz/#!7wJ2hLTA!q_b9PDpj_K9g … NrqWGvGlro

Please also note that inserting the last JSON data "ProfileID" as Cardinal in any position into the record definition solved the problem.

Any JSON item not correspond to the RTTI schema should be ignored.

Regards

Offline

#4 2018-01-31 19:35:51

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,659
Website

Re: JSON Parse problem

You could please explain a little bit what the problem is?
I don't understand it, sorry.

Perhaps write and post a link to some ready-to-be used regression program.

Offline

#5 2018-01-31 19:49:59

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 37

Re: JSON Parse problem

Would please test the attached program?

The commented text located above then "ProfileID" definition related to the TAffiliate record.

https://mega.nz/#!L1IygQRT!-plkrXfdJISG … sne42MK1M4

Offline

#6 2018-02-01 09:29:31

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 37

Re: JSON Parse problem

Simply commented the validation line:
FirstChar := JSON^;
    JSON := Reader(JSON,Rec,wasValid);
//    if not wasValid then exit;

Solved the problem which is treated as follows:
The parse continues even the current field doesn't exist in the RTTI schema (Record definition).

Would you please confirm?

Regards

Offline

#7 2018-02-06 09:33:54

Hafedh TRIMECHE
Member
Registered: 2016-09-18
Posts: 37

Re: JSON Parse problem

By activating this option, the problem is solved soReadIgnoreUnknownFields
    TTextWriter.RegisterCustomJSONSerializerSetOptions(TypeInfo(T),[soReadIgnoreUnknownFields]);

Offline

Board footer

Powered by FluxBB