23
Сен
2020

api возвращает строку в виде массива

API возвращает данные стройкой, в свою очередь строка в виде массива, такого вида:

{"Stages":[{"Events":[{"T1":[{"ID":10205,"I":[{"P":1,"Id":10205},{"P":2,"Id":999},{"P":5,"Id":999},{"P":6,"Id":2819},{"P":7,"Id":1238}],"Kn":1,"Gd":1,"Nm":"Villarreal"}],"Tr1":"2","Trh1":"0","T2":[{"ID":8372,"I":[{"P":1,"Id":8372},{"P":2,"Id":436},{"P":5,"Id":436},{"P":6,"Id":2839},{"P":7,"Id":1344}],"Kn":1,"Gd":1,"Nm":"Eibar"}],"Tr2":"1","Trh2":"0","IDs":[{"P":1,"ID":3424057,"d":1,"Sid":869369}],"Sg":1,"Esd":20200919210000,"Esid":6,"Epr":2,"Eps":"FT","Ewt":1,"Ern":2,"EO":25123},{"T1":[{"ID":8305,"I":[{"P":1,"Id":8305},{"P":2,"Id":488},{"P":5,"Id":488},{"P":6,"Id":2859},{"P":7,"Id":1029}],"Kn":1,"Gd":1,"Nm":"Getafe"}],"Tr1":"1","Trh1":"0","T2":[{"ID":8371,"I":[{"P":1,"Id":8371},{"P":2,"Id":742},{"P":5,"Id":742},{"P":6,"Id":2820},{"P":7,"Id":434}],"Kn":1,"Gd":1,"Nm":"Osasuna"}],"Tr2":"0","Trh2":"0","IDs":[{"P":1,"ID":3424051,"d":1,"Sid":869369}],"Sg":1,"Esd":20200919233000,"Esid":6,"Epr":2,"Eps":"FT","Ewt":1,"Ern":2,"EO":25123},{"T1":[{"ID":9910,"I":[{"P":1,"Id":9910},{"P":2,"Id":354},{"P":5,"Id":354},{"P":6,"Id":2821},{"P":7,"Id":281}],"Kn":1,"Gd":1,"Nm":"Celta Vigo"}],"Tr1":"2","Trh1":"1","T2":[{"ID":10267,"I":[{"P":1,"Id":10267},{"P":2,"Id":978},{"P":5,"Id":978},{"P":6,"Id":2828},{"P":7,"Id":1336}],"Kn":1,"Gd":1,"Nm":"Valencia"}],"Tr2":"1","Trh2":"0","IDs":[{"P":1,"ID":3424050,"d":1,"Sid":869369}],"Sg":1,"Esd":20200920020000,"Esid":6,"Epr":2,"Eps":"FT","Ewt":1,"Ern":2,"EO":25123},{"T1":[{"ID":96925,"I":[{"P":1,"Id":96925},{"P":2,"Id":27681},{"P":5,"Id":27681},{"P":6,"Id":24265},{"P":7,"Id":3504}],"Kn":1,"Gd":1,"Nm":"SD Huesca"}],"Tr1":"0","Trh1":"0","T2":[{"ID":8385,"I":[{"P":1,"Id":8385},{"P":2,"Id":2582},{"P":5,"Id":2582},{"P":6,"Id":4488},{"P":7,"Id":408}],"Kn":1,"Gd":1,"Nm":"Cadiz"}],"Tr2":"2","Trh2":"1","IDs":[{"P":1,"ID":3424053,"d":1,"Sid":869369}],"Sg":1,"Esd":20200920210000,"Esid":6,"Epr":2,"Eps":"FT","Ewt":2,"Ern":2,"EO":25123},{"T1":[{"ID":8581,"I":[{"P":1,"Id":8581},{"P":2,"Id":617},{"P":5,"Id":617},{"P":6,"Id":2849},{"P":7,"Id":1160}],"Kn":1,"Gd":1,"Nm":"Levante"}],"T2":[{"ID":9906,"I":[{"P":1,"Id":9906},{"P":2,"Id":258},{"P":5,"Id":258},{"P":6,"Id":2836},{"P":7,"Id":435}],"Kn":1,"Gd":1,"Nm":"Atletico Madrid"}],"IDs":[{"P":1,"ID":3424054,"d":1,"Sid":869369}],"Sg":1,"Esd":20200920220000,"Esid":5,"Epr":4,"Eps":"Postp.","Ern":2,"EO":24576},{"T1":[{"ID":8302,"I":[{"P":1,"Id":8302},{"P":2,"Id":859},{"P":5,"Id":859},{"P":6,"Id":2833},{"P":7,"Id":182}],"Kn":1,"Gd":1,"Nm":"Sevilla"}],"T2":[{"ID":10268,"I":[{"P":1,"Id":10268},{"P":2,"Id":439},{"P":5,"Id":439},{"P":6,"Id":2846},{"P":7,"Id":294}],"Kn":1,"Gd":1,"Nm":"Elche"}],"IDs":[{"P":1,"ID":3424056,"d":1,"Sid":869369}],"Sg":1,"Esd":20200920220000,"Esid":5,"Epr":4,"Eps":"Postp.","Ern":2,"EO":24576},{"T1":[{"ID":7878,"I":[{"P":1,"Id":7878},{"P":2,"Id":2001},{"P":5,"Id":2001},{"P":6,"Id":33779},{"P":7,"Id":5437}],"Kn":1,"Gd":1,"Nm":"Granada"}],"Tr1":"2","Trh1":"1","T2":[{"ID":9866,"I":[{"P":1,"Id":9866},{"P":2,"Id":223},{"P":5,"Id":223},{"P":6,"Id":2885},{"P":7,"Id":638}],"Kn":1,"Gd":1,"Nm":"Deportivo Alaves"}],"Tr2":"1","Trh2":"1","IDs":[{"P":1,"ID":3424052,"d":1,"Sid":869369}],"Sg":1,"Esd":20200920233000,"Esid":6,"Epr":2,"Eps":"FT","Ewt":1,"Ern":2,"EO":25123},{"T1":[{"ID":8603,"I":[{"P":1,"Id":8603},{"P":2,"Id":292},{"P":5,"Id":292},{"P":6,"Id":2816},{"P":7,"Id":746}],"Kn":1,"Gd":1,"Nm":"Real Betis"}],"Tr1":"2","Trh1":"2","T2":[{"ID":10281,"I":[{"P":1,"Id":10281},{"P":2,"Id":980},{"P":5,"Id":980},{"P":6,"Id":2831},{"P":7,"Id":136}],"Kn":1,"Gd":1,"Nm":"Real Valladolid"}],"Tr2":"0","Trh2":"0","IDs":[{"P":1,"ID":3424049,"d":1,"Sid":869369}],"Sg":1,"Esd":20200920233000,"Esid":6,"Epr":2,"Eps":"FT","Ewt":1,"Ern":2,"EO":25123},{"T1":[{"ID":8560,"I":[{"P":1,"Id":8560},{"P":2,"Id":879},{"P":5,"Id":879},{"P":6,"Id":2824},{"P":7,"Id":1264}],"Kn":1,"Gd":1,"Nm":"Real Sociedad"}],"Tr1":"0","T2":[{"ID":8633,"I":[{"P":1,"Id":8633},{"P":2,"Id":803},{"P":5,"Id":803},{"P":6,"Id":2829},{"P":7,"Id":696}],"Kn":1,"Gd":1,"Nm":"Real Madrid"}],"Tr2":"0","IDs":[{"P":1,"ID":3424055,"d":1,"Sid":869369}],"Sg":1,"Esd":20200921020000,"Esid":6,"Epr":2,"Eps":"FT","Ern":2,"EO":25123}],"Cid":42,"Ccd":"spain","Cnm":"Spain","Chi":0,"Ccntr":1,"Clive":1,"Sid2":198,"Scd":"primera-division","Sdn":"LaLiga Santander","Snm":"LaLiga Santander","Sds":"LaLiga","Ssm":750,"Scu":0,"SmCLT":750,"Slive":1,"Ses":380,"Spps":20}

Не могу понять как перебирать строку, что бы получить нужные данные, например нужно вытащить из данной строки "Villarreal", знаю что можно сделать поиск вхождений и регулярками вытягивать, но кажется это костыль, хотелось бы циклом вытягивать нужные данные

Источник: https://ru.stackoverflow.com/questions/1181722/api-%D0%B2%D0%BE%D0%B7%D0%B2%D1%80%D0%B0%D1%89%D0%B0%D0%B5%D1%82-%D1%81%D1%82%D1%80%D0%BE%D0%BA%D1%83-%D0%B2-%D0%B2%D0%B8%D0%B4%D0%B5-%D0%BC%D0%B0%D1%81%D1%81%D0%B8%D0%B2%D0%B0

Тебе может это понравится...

Добавить комментарий