I am requesting json file every few seconds and it's sometimes quite big, so is it possible to somehow retrieve not the whole json file, but just the last element? getJson gets the whole file.

有帮助吗?

解决方案

No, you must fetch the entire file before you can parse it and return only the last element. The best solution here is to create a new JSON file with only the information you need (if you have that ability).

其他提示

Not unless you either:

  • Modify the service to provide only the last element, possibly at a different URL/using parameters.
  • Know exactly how long the data before the last element will be, allowing you to do a [RANGE][1] request to the server

Of course, with the second method, the last element on its own is likely not a valid JSON object (not guaranteed to be enclosed in curly braces) so you'll need to manipulate it before parsing it

Well you can't access partial json from javascript. You have to do it on the server side. Just create a new php function that reads the last element and access it from getJson

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top