简体   繁体   中英

Super Object - spaces in element names

I'm using Super Object as a JSON parser. I ran into a problem while working with a third-party API. The API returns JSON with spaces in the element names. However, Super Object does not work with spaces. I observed behavior where it treats the space as the end quote, thus ignoring anything after the space.

{ "state abbreviation":"KY", "state":"Kentucky" }

I believe the key is that state is also the name of another element. When I try to read state abbreviation it returns the value of state instead.

How can I get around this problem?

This MCVE indicates that SuperObject is working correctly with spaces in the name of the element, I used the latest version of the source code and Delphi XE7:

program SO40958627;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  SuperObject,
  System.SysUtils;

var
  obj: ISuperObject;

begin
  try
   obj := SO('{ "state":"Kentucky", "state abbreviation":"KY" }');
   Writeln(obj.AsObject.S['state']);
   Writeln(obj.AsObject.S['state abbreviation']);
   Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Output from program:

Kentucky 
KY

It seems that you are not using the latest version of the source code, or that the defect is located elsewhere in your program...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM