[Solved] How do I loop through large JSON lists?

It’s really strange and bugs me.
The program works just fine when the index of loop is 5 or 10 .
But it was just crushed when I set the index to the length of an object.
I need to clear the cookies so that I can continue to run the program.
Any advice?

Here is the demo.

My code

1 Like

Is the top level of the JSON response an array/list? Because if it isn’t, this won’t work.

Post the text of your JSON response.

2 Likes

Hi
The JSON response is from the request url.

[{"StopUID":"NWT138796","StopID":"138796","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16588","RouteID":"16588","RouteName":{"Zh_tw":"264","En":"264"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT123513","StopID":"123513","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16423","RouteID":"16423","RouteName":{"Zh_tw":"930","En":"930"},"Direction":1,"EstimateTime":766,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT178949","StopID":"178949","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17523","RouteID":"17523","RouteName":{"Zh_tw":"806","En":"806"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT178643","StopID":"178643","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17517","RouteID":"17517","RouteName":{"Zh_tw":"99","En":"99"},"Direction":1,"EstimateTime":631,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT140070","StopID":"140070","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16603","RouteID":"16603","RouteName":{"Zh_tw":"920","En":"920"},"Direction":1,"EstimateTime":88,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT149611","StopID":"149611","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16689","RouteID":"16689","RouteName":{"Zh_tw":"793","En":"793"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT140846","StopID":"140846","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16614","RouteID":"16614","RouteName":{"Zh_tw":"930延","En":"930Extend"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT149286","StopID":"149286","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16685","RouteID":"16685","RouteName":{"Zh_tw":"657延","En":"657sub"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT199118","StopID":"199118","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17668","RouteID":"17668","RouteName":{"Zh_tw":"982","En":"982"},"Direction":1,"EstimateTime":1898,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT199116","StopID":"199116","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17679","RouteID":"17679","RouteName":{"Zh_tw":"982區","En":"982Shuttle"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT34188","StopID":"34188","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10151","RouteID":"10151","RouteName":{"Zh_tw":"701","En":"701"},"Direction":0,"EstimateTime":1097,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT208906","StopID":"208906","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT18729","RouteID":"18729","RouteName":{"Zh_tw":"920副","En":"920Sub"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT15107","StopID":"15107","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10162","RouteID":"10162","RouteName":{"Zh_tw":"245","En":"245"},"Direction":0,"EstimateTime":752,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT15842","StopID":"15842","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10163","RouteID":"10163","RouteName":{"Zh_tw":"656","En":"656"},"Direction":0,"EstimateTime":355,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT15980","StopID":"15980","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT10164","RouteID":"10164","RouteName":{"Zh_tw":"657","En":"657"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT179283","StopID":"179283","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17527","RouteID":"17527","RouteName":{"Zh_tw":"813區","En":"813Shuttle"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT179236","StopID":"179236","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT17526","RouteID":"17526","RouteName":{"Zh_tw":"813","En":"813"},"Direction":1,"EstimateTime":1149,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT127415","StopID":"127415","StopName":{"Zh_tw":"中山國中","En":"JhongShan Junior High School"},"RouteUID":"NWT16462","RouteID":"16462","RouteName":{"Zh_tw":"910","En":"910"},"Direction":1,"EstimateTime":984,"StopStatus":0,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT127445","StopID":"127445","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16463","RouteID":"16463","RouteName":{"Zh_tw":"藍35","En":"BL35"},"Direction":0,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT127876","StopID":"127876","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT16471","RouteID":"16471","RouteName":{"Zh_tw":"藍33","En":"BL33"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"},{"StopUID":"NWT205981","StopID":"205981","StopName":{"Zh_tw":"中山國中","En":"Zhongshan Junior High School"},"RouteUID":"NWT18318","RouteID":"18318","RouteName":{"Zh_tw":"918區","En":"918Shuttle"},"Direction":1,"StopStatus":3,"SrcUpdateTime":"2022-03-31T22:34:20+08:00","UpdateTime":"2022-03-31T22:34:23+08:00"}]
1 Like

I just made a quick test and it worked fine.

Output
image

[Note]
I noticed that first entry does not have EstimateTime field and this could cause errors when parsing.

1 Like

Thank you so much.
Bug fixed after I notice your [Note] :grinning: :grinning: :grinning:
Here is modified code.

The original code doesn’t work when the EstimateTime is null.

1 Like

I would do it this way

The output would be like this
image

3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.