Jump to content
grantful

Remove quotes from a string

Recommended Posts

I am doing a json query and getting the objects

the strings i am getting back have quotes around them

example

"bloody mary", "Mararita", "old fasion", etc

 

I am using the split finction to remove the quotes and it works gooed

 

 

My problem is when i load the strings into a listbox or memo it get an item and then 2 spaces , an items and 2 more spaces, etc

 

tomanyspaces.thumb.png.0c689cb030fd7aace8bdc51d935bf46f.png

 

 

Has anyone run into this problem ?

 

As always thanks for any help and comments.

 

Share this post


Link to post
28 minutes ago, grantful said:

Has anyone run into this problem ?

Not when using classes that parse the JSON (at least, properly), since they won't include the quotes (given your example). What code are you using to parse it?

Share this post


Link to post

Use TJsonValue.AsString instead of .ToString and your values will be properly converted and dequoted.

Share this post


Link to post

Looks like your json parsing code is wrong but you didn't show any code. Very hard for us to say what's wrong with your code when we can't see it. Don't be shy. 

  • Haha 1

Share this post


Link to post

Thanks for the comments. I can not believe i forgot to show the code 😞

procedure TForm2.findReciepeClick(Sender: TObject);
  const  Delim: String = '"';
var
  MainJson, Result: TJSONObject;
  reslultListbox: TJSONArray;
  s: TArray<string>;
  SrcString: String ;

begin
  Form2.RESTClient1.BaseURL :=
    'https://www.thecocktaildb.com/api/json/v1/1/search.php?s=' + Edit7.Text;
  Form2.RESTRequest1.Execute;
  Memo4.Text := Form2.RESTResponse1.JSONText;

  Result := TJSONObject.ParseJSONValue(Form2.RESTResponse1.Content)
    as TJSONObject;

  reslultListbox := Result.GetValue('drinks') as TJSONArray;

  for var JSONValue in reslultListbox do

  begin
      SrcString := (JSONValue as TJSONObject).GetValue('strDrink').ToString;

     s := SrcString.Split(Delim);

     ListBox1.Items.AddStrings(s);

  end;

  MainJson := Result.GetValue<TJSONObject>('drinks[0]');
  Edit8.Text := MainJson.GetValue<string>('strDrink');

  MainJson := Result.GetValue<TJSONObject>('drinks[0]');
  Memo5.Text := MainJson.GetValue<string>('strInstructions');

end;

 

Share this post


Link to post
4 hours ago, aehimself said:

Use TJsonValue.AsString instead of .ToString and your values will be properly converted and dequoted.

SrcString := (JSONValue as TJSONObject).GetValue('strDrink').AsType<string>;

 

this fixed it. 

Thanks for all your guys help and time.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×