1
I’m getting a stream with JSON strings and I’m showing on a Tmemo. It happens that I am not able to process the JSON correctly because not always comes the same amount of characters from the server. I would need to process the JSON and display the results in another TMEMO. I’ve heard of buffer, streams etc but I’m not familiar with them.
Note: Use Tclientsocket
procedure TForm1.csClienteRead(Sender: TObject; Socket: TCustomWinSocket);
var
data: String;
begin
data := Socket.ReceiveText;
memoResults.Lines.Add(data);
end;
As soon as I connect the Customer’s connection I receive this data:
{ "age" : "0", "camera" : "0", "direction" : "===", "id" : "12", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328838" }
{ "age" : "0", "camera" : "0", "direction" : "===", "id" : "11", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328838" }
{ "age" : "1", "camera" : "0", "direction" : "===", "id" : "10", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328837" }
{ "age" : "1", "camera" : "0", "direction" : "===", "id" : "9", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328837" }
{ "age" : "2", "camera" : "0", "direction" : "===", "id" : "8", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328836" }
{ "age" : "2", "camera" : "0", "direction" : "===", "id" : "7", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328836" }
{ "age" : "3", "camera" : "0", "direction" : "===", "id" : "6", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328835" }
{ "age" : "3", "camera" : "0", "direction" : "===", "id" : "5", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328835" }
{ "age" : "4", "camera" : "0", "direction" : "===", "id" : "4", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328834" }
{ "age" : "4", "camera" : "0", "direction" : "===", "id" : "3", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1508328834" }
{ "age" : "16402735", "camera" : "0", "direction" : ">>>", "id" : "0", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926103" }
{ "age" : "16402735", "camera" : "0", "direction" : "===", "id" : "2", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926103" }
{ "age" : "16402736", "camera" : "0", "direction" : "===", "id" : "1", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926102" }
{ "age" : "16402736", "camera" : "0", "direction" : "===", "id" : "0", "plate" : "DEMOPLATE", "strength" : "0.66 - 1.00 0.90 1.00 0.66 1.00 0.90 1.00", "systemName" : "AUTOPARKING", "timestamp" : "1491926102" }
After this starts coming line by line but sometimes everything comes together without line breaks. I need 1 JSON at a time otherwise the system does not process.
What else is the least JSON structure? Adds a JSON answer to the question
– Tmc
See if this helps you’ll need something like this: https://answall.com/questions/237277/replacer-palavras-ao-importa-no-listview/237354#237354
– Tmc
Exactly as @Tmc mentioned, post the structure of JSON that is receiving, if it contradicts this very broad your question!
– Junior Moreira
@Tmc I edited the question with the return of JSON
– Ezequiel Tavares