grantful 3 Posted August 9, 2023 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 Has anyone run into this problem ? As always thanks for any help and comments. Share this post Link to post
Dave Nottage 557 Posted August 9, 2023 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
aehimself 396 Posted August 9, 2023 Use TJsonValue.AsString instead of .ToString and your values will be properly converted and dequoted. Share this post Link to post
David Heffernan 2345 Posted August 9, 2023 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. 1 Share this post Link to post
grantful 3 Posted August 9, 2023 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
grantful 3 Posted August 9, 2023 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