The php script loads html encoded into json from a third-party service, sometimes, for various reasons, the incomplete answer comes (slow connection) and json is not validated by standard php functions, for example json_decode. It is very important for the script to know what has come, even if this answer is not fully received. Advise how to get data from invalid json?

A simple example, the answer json should contain 25 links, but json loaded only 10, and broke off at 11, how to get these 10 links?

  • one
  • it’s not completely like this: [ 'http://gogle.com', 'http://yandex.ru', 'http://bing' and further body is '.com', ...., ]' missing? - teran
  • for what reason you can not send a second request, if the first returned the curve result - teran
  • yes, just like that, only the links are in some html code containing different attributes, there is no time to re-request, you need to process what is - user193361
  • The obvious answer to this question would be that either you yourself must bring a piece of data to a valid format, or you need to find a library that does it for you. There are obviously no other ways, and never will be. Perhaps, if processing of a strictly typed file is required, then you can rip out links with their surroundings using regular expressions, generally scoring on the Json format. If you have a lot of different data come, then of course the option will not work. - teran

0