2

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?

Jerry Dodge
  • 26,858
  • 31
  • 155
  • 327

1 Answers1

2

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...

whosrdaddy
  • 11,720
  • 4
  • 50
  • 99
  • See my comments and answer under [my question here](https://stackoverflow.com/questions/18445280/superobject-cannot-handle-null-string) regarding the availability of SuperObject versions – Jan Doggen Aug 01 '18 at 21:16