Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2013-01

FPJSONRTTI: Case insensitive.

6 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

silvioprog

Hello,

I have this JSON:

{ "id": 1, "name": "Silvio Clécio" }

And my object is:

TPerson = class
private
  FID: Int64;
  FName: string;
published
  property ID: Int64 read FID write FID;
  property Name: string read FName write FName;
end;

But, FPJSONRTTI don't find the fields, except if I change my class to:

  property id: Int64 read FID write FID;
  property name: string read FName write FName;

Or my JSON to:

{ "ID": 1, "Name": "Silvio Clécio" }

So, how to I find all fields but in case insensitive? (like TypInfo functions)

Thank you!

ps. Marshal of Delphi is case insensitive.

ps2. So, I send this my questions only to fpc-devel or fpc-pascal? :/

Silvio Clécio My public projects - github.com/silvioprog
Michael Van Canneyt
to silvioprog
silvioprog wrote 5 lines
Hello, I have this JSON: { "id": 1, "name": "Silvio Clécio" }

JSON is JavaScript and JavaScript *is* case sensitive.

But you can use TJSONObject.IndexOfName with CaseInsentive to True:

     Function IndexOfName(const AName: TJSONStringType; CaseInsensitive : Boolean = False): Integer;

Line 450 of fpjsonrtti could be changed to set this to True, but it will have a bad impact on performance. Maybe we can have a property for this.

You should fix your incoming JSON instead.

Michael.

silvioprog
to Michael Van Canneyt

2013/1/24 Michael Van Canneyt

[...] Maybe we can have a property for this.

This would be an excellent idea. This new property could be to False by default.

I'll open an issue about this.

Silvio Clécio My public projects - github.com/silvioprog
silvioprog
to Michael Van Canneyt

2013/1/24 Michael Van Canneyt

Show quoted text 15 lines
On Thu, 24 Jan 2013, silvioprog wrote:2013/1/24 Michael Van Canneyt < > > [...] > Maybe we can have a property for this. > > This would be an excellent idea. This new property could be to False by > default. > > I'll open an issue about this. > Implemented it. Please test and close the bugreport if OK. Michael.

Worked fine. Thank you! :)

Silvio Clécio My public projects - github.com/silvioprog