문제

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