如何将 JSON 字符串转换为 JSON 数组列表? [复制]

Posted

技术标签:

【中文标题】如何将 JSON 字符串转换为 JSON 数组列表? [复制]【英文标题】:How to convert a JSON string into a JSON arraylist? [duplicate] 【发布时间】:2019-03-08 16:33:47 【问题描述】:

我有一个字符串,我想在列表中显示它,所以我必须在数组列表中转换它 我该怎么做? 这些东西我都试过了

     String Result =response.body().getGetFlightAvailibilityResponse().getGetFlightAvailibilityResult().getGetFlightAvailibilityResponse().getFlightDetails();
                    try 




                        Gson gson = new Gson();
                        Type type = new TypeToken<List<Object>>() 
                        .getType();
                        List<String> contactList = gson.fromJson(Result, 
                        type);


                      //  JSONArray jsonArray = new JSONArray(Result);
                     catch (Exception e) 
                        e.printStackTrace();
                     

这是我的字符串

[[SrNo,AirlineCode,FlightNo,FromAirportCode,ToAirportCode,DepDate,DepTime,ArrDate,ArrTime,FlightClass,FlightTime,TotalAmount,TaxAmount,Stops,ValCarrier,FromTerminal,ToTerminal,MainClass,FareBasis,AgencyCharge,FareType,AvailSeats,FlightRemarks ,TrackNo],[100YO,9W,346,BOM,DEL,04/10/2018,07:30,04/10/2018,09:40,O,130,3998,1798,0,9W,2, 3,Y,,0,N,0,,0$307|37|100YO],[101YO,9W,953,BOM,JAI,04/10/2018,14:35,04/10/2018,16:30 ,O,115,4550,1949,1,9W,2, 2,Y,,0,N,0,,0$307|37|101YO],[101YO,9W,788,JAI,DEL,04/10/2018,17:00,04/10/2018,18:05 ,O,65,0,0,0,9W,2, 3,Y,,0,N,0,,0$307|37|101YO],[102YO,9W,2418,BOM,JAI,04/10/2018,18:20,04/10/2018,20:10 ,O,110,4550,1949,1,9W,2, 2,Y,,0,N,0,,0$307|37|102YO],[102YO,9W,756,JAI,DEL,04/10/2018,21:15,04/10/2018,22:20 ,O,65,0,0,0,9W,2, 3,Y,,0,N,0,,0$307|37|102YO],[103YO,9W,309,BOM,DEL,04/10/2018,19:00,04/10/2018,21:15 ,V,135,4995,1845,0,9W,2, 3,Y,,0,N,0,,0$307|37|103YO],[104YO,9W,2374,BOM,LKO,04/10/2018,12:25,04/10/2018,14:45 ,W,140,​​5053,2573,1,9W,2, 2,Y,,0,N,0,,0$307|37|104YO],[104YO,9W,856,LKO,DEL,04/10/2018,15:40,04/10/2018,17:00 ,W,80,0,0,0,9W,2, 3,Y,,0,N,0,,0$307|37|104YO],[105YO,9W,2929,BOM,AMD,04/10/2018,02:50,04/10/2018,04:00 ,H,70,5315,1985,1,9W,2, 1,Y,,0,N,0,,0$307|37|105YO],[105YO,9W,685,AMD,DEL,04/10/2018,05:35,04/10/2018,07:20 ,H,105,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|105YO],[106YO,9W,385,BOM,IDR,04/10/2018,17:35,04/10/2018,18:55 ,V,80,6229,2029,1,9W,2,,Y,,0,N,0,,0$307|37|106YO],[106YO,9W,794,IDR,DEL,04/10/2018 ,20:20,04/10/2018,22:50,V,150,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|106YO],[107YO,9W,2377,BOM,RPR,04/10/2018,06:35,04/10/2018,08:30 ,V,115,6329,2034,1,9W,2,,Y,,0,N,0,,0$307|37|107YO],[107YO,9W,2735,RPR,DEL,04/10/2018 ,09:00,04/10/2018,10:50,V,110,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|107YO],[108YO,9W,895,BOM,BHO,04/10/2018,18:40,04/10/2018,20:10 ,V,90,6743,2053,1,9W,2,,Y,,0,N,0,,0$307|37|108YO],[108YO,9W,928,BHO,DEL,04/10/2018 ,21:00,04/10/2018,22:25,V,85,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|108YO],[109YO,9W,2967,BOM,RPR,04/10/2018,17:25,04/10/2018,19:25 ,V,120,7016,2066,1,9W,2,,Y,,0,N,0,,0$307|37|109YO],[109YO,9W,2677,RPR,DEL,04/10/2018 ,20:05,04/10/2018,21:55,V,110,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|109YO],[10YO,SG,153,BOM,COK,04/10/2018,09:30,04/10/2018,11:30 ,C,120,7334,725,1,SG,1, 1,Y,,500,R,0,,0$307|37|10YO],[10YO,SG,184,COK,DEL,04/10/2018,13:45,04/10/2018,18:00 ,C,255,0,0,1,SG,1,,Y,,0,R,0,,0$307|37|10YO],[110YO,9W,413,BOM,BLR,04/10/2018 ,16:30,04/10/2018,18:15,H,105,7724,2959,1,9W,2,,Y,,0,N,0,,0$307|37|110YO],[110YO ,9W,833,BLR,DEL,04/10/2018,18:55,04/10/2018,21:50,H,175,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|110YO],[111YO,9W,703,BOM,DED,04/10/2018,11:00,04/10/2018,13:15 ,K,135,11531,2881,1,9W,2,,Y,,0,N,0,,0$307|37|111YO],[111YO,9W,150,DED,DEL,04/10/2018 ,13:50,04/10/2018,15:10,K,80,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|111YO],[112YO,9W,701,BOM,DED,04/10/2018,13:05,04/10/2018,15:20 ,M,135,36278,4060,1,9W,2,,Y,,0,N,0,,0$307|37|112YO],[112YO,9W,186,DED,DEL,04/10/2018 ,17:10,04/10/2018,18:20,M,70,0,0,0,9W,, 3,Y,,0,N,0,,0$307|37|112YO],[11YO,SG,153,BOM,COK,04/10/2018,09:30,04/10/2018,11:30 ,C,120,9854,1245,1,SG,1, 1,Y,,500,R,0,,0$307|37|11YO],[11YO,SG,184,COK,DEL,04/10/2018,13:45,04/10/2018,18:00 ,C,255,0,0,1,SG,1,,Y,,0,R,0,,0$307|37|11YO],[12YO,SG,153,BOM,COK,04/10/2018 ,09:30,04/10/2018,11:30,E,120,10274,1265,1,SG,1, 1,Y,,500,R,0,,0$307|37|12YO],[12YO,SG,184,COK,DEL,04/10/2018,13:45,04/10/2018,18:00 ,C,255,0,0,1,SG,1,,Y,,0,R,0,,0$307|37|12YO],[13YO,AI,217,BOM,DEL,04/10/2018 ,10:25,04/10/2018,11:45,S,80,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|13YO],[14YO, AI,61,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555,0,AI,,,Y,,0,N,0 ,,0$307|37|14YO],[15YO,AI,66,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555,0 ,AI,,,Y,,0,N,0,,0$307|37|15YO],[16YO,AI,67,BOM,DEL,04/10/2018,01:00,04/10/2018, 02:30,S,90,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|16YO],[17YO,AI,107,BOM,DEL,04/10 /2018,01:00,04/10/2018,02:30,S,90,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|17YO],[ 18YO,AI,212,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555,0,AI,,,Y,,0,N ,0,,0$307|37|18YO],[19YO,AI,323,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555 ,0,AI,,,Y,,0,N,0,,0$307|37|19YO],[1YO,SG,160,BOM,DEL,04/10/2018,06:00,04/10/ 2018,07:55,H,115,2811,711,0,SG,1, 1C,Y,,500,R,0,,0$307|37|1YO],[20YO,AI,326,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30 ,S,90,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|20YO],[21YO,AI,455,BOM,DEL,04/10/2018, 01:00,04/10/2018,02:30,S,90,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|21YO],[22YO,AI ,523,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555,0,AI,,,Y,,0,N,0, ,0$307|37|22YO],[23YO,AI,752,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555,0, AI,,,Y,,0,N,0,,0$307|37|23YO],[24YO,AI,789,BOM,DEL,04/10/2018,01:00,04/10/2018,02 :30,S,90,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|24YO],[25YO,AI,801,BOM,DEL,04/10/ 2018,01:00,04/10/2018,02:30,S,90,4255,555,0,AI,2,,Y,,0,N,0,,0$307|37|25YO],[ 26YO,AI,802,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30,S,90,4255,555,0,AI,, 3,Y,,0,N,0,,0$307|37|26YO],[27YO,AI,1111,BOM,DEL,04/10/2018,01:00,04/10/2018,02:30 ,S,90,4255,555,0,AI,, 3,Y,,0,N,0,,0$307|37|27YO],[28YO,AI,300,BOM,DEL,04/10/2018,03:00,04/10/2018,04:30 ,S,90,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|28YO],[29YO,AI,256,BOM,DEL,04/10/2018, 00:10,04/10/2018,01:45,S,95,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|29YO],[2YO,SG ,160,BOM,DEL,04/10/2018,06:00,04/10/2018,07:55,C,115,3021,521,0,SG,1, 1C,Y,,500,R,0,,0$307|37|2YO],[30YO,AI,257,BOM,DEL,04/10/2018,00:10,04/10/2018,01:45 ,S,95,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|30YO],[31YO,AI,5011,BOM,DEL,04/10/2018, 00:10,04/10/2018,02:10,S,120,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|31YO],[32YO,AI ,97,BOM,DEL,04/10/2018,06:00,04/10/2018,08:00,S,120,4255,555,0,AI,,,Y,,0,N,0, ,0$307|37|32YO],[33YO,AI,98,BOM,DEL,04/10/2018,06:00,04/10/2018,08:00,S,120,4255,555,0,人工智能,2, 3,Y,,0,N,0,,0$307|37|33YO],[34YO,AI,99,BOM,DEL,04/10/2018,06:00,04/10/2018,08:00 ,S,120,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|34YO],[35YO,AI,4141,BOM,DEL,04/10/2018, 10:00,04/10/2018,12:00,S,120,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|35YO],[36YO,AI ,3,BOM,DEL,04/10/2018,12:00,04/10/2018,14:00,S,120,4255,555,0,AI,,,Y,,0,N,0, ,0$307|37|36YO],[37YO,AI,864,BOM,DEL,04/10/2018,07:00,04/10/2018,09:05,S,125,4255,555,0,人工智能,2, 3,Y,,0,N,0,,0$307|37|37YO],[38YO,AI,144,BOM,DEL,04/10/2018,17:00,04/10/2018,19:10 ,S,130,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|38YO],[39YO,AI,101,BOM,DEL,04/10/2018,21:00,04/10/2018,23:10 ,S,130,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|39YO],[3YO,SG,152,BOM,DEL,04/10/2018,07:20,04/10/2018,09:35 ,H,135,2811,711,0,SG,1, 1C,Y,,500,R,0,,0$307|37|3YO],[40YO,AI,200,BOM,DEL,04/10/2018,21:00,04/10/2018,23:10 ,S,130,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|40YO],[41YO,AI,232,BOM,DEL,04/10/2018, 05:15,04/10/2018,07:30,S,135,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|41YO],[42YO,AI ,348,BOM,DEL,04/10/2018,07:55,04/10/2018,10:10,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|42YO],[43YO,AI,806,BOM,DEL,04/10/2018,08:00,04/10/2018,10:15 ,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|43YO],[44YO,AI,809,BOM,DEL,04/10/2018,10:00,04/10/2018,12:15 ,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|44YO],[45YO,AI,677,BOM,DEL,04/10/2018,13:00,04/10/2018,15:15 ,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|45YO],[46YO,AI,687,BOM,DEL,04/10/2018,16:00,04/10/2018,18:15 ,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|46YO],[47YO,AI,310,BOM,DEL,04/10/2018,19:45,04/10/2018,22:00 ,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|47YO],[48YO,AI,866,BOM,DEL,04/10/2018,09:00,04/10/2018,11:25 ,S,145,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|48YO],[49YO,AI,660,BOM,DEL,04/10/2018,18:00,04/10/2018,20:25 ,S,145,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|49YO],[4YO,SG,152,BOM,DEL,04/10/2018,07:20,04/10/2018,09:35 ,C,135,3021,521,0,SG,1, 1C,Y,,500,R,0,,0$307|37|4YO],[50YO,AI,555,BOM,DEL,04/10/2018,01:00,04/10/2018,03:30 ,S,150,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|50YO],[51YO,AI,666,BOM,DEL,04/10/2018,01:00,04/10/2018,03:30 ,S,150,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|51YO],[52YO,AI,2123,BOM,DEL,04/10/2018, 01:00,04/10/2018,03:30,S,150,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|52YO],[53YO,AI ,150,BOM,DEL,04/10/2018,05:00,04/10/2018,07:30,S,150,4255,555,0,AI,,,Y,,0,N,0, ,0$307|37|53YO],[54YO,AI,100,BOM,DEL,04/10/2018,07:00,04/10/2018,09:30,S,150,4255,555,0, AI,,,Y,,0,N,0,,0$307|37|54YO],[55YO,AI,85,BOM,DEL,04/10/2018,12:00,04/10/2018,14 :30,S,150,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|55YO],[56YO,AI,5190,BOM,DEL,04/10/ 2018,21:00,04/10/2018,23:30,S,150,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|56YO],[57YO ,AI,5191,BOM,DEL,04/10/2018,21:00,04/10/2018,23:30,S,150,4255,555,0,AI,,,Y,,0,N, 0,,0$307|37|57YO],[58YO,AI,250,BOM,DEL,04/10/2018,01:00,04/10/2018,04:00,S,180,4255,555, 0,AI,,,Y,,0,N,0,,0$307|37|58YO],[59YO,AI,2323,BOM,DEL,04/10/2018,01:00,04/10/2018 ,04:00,S,180,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|59YO],[5YO,SG,158,BOM,DEL,04/ 10/2018,18:45,04/10/2018,20:5 5,H,130,2811,711,0,SG,1, 1C,Y,,500,R,0,,0$307|37|5YO],[60YO,AI,5578,BOM,DEL,04/10/2018,20:00,04/10/2018,23:00 ,S,180,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|60YO],[61YO,AI,5580,BOM,DEL,04/10/2018, 20:00,04/10/2018,23:00,S,180,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|61YO],[62YO,AI ,413,BOM,DEL,04/10/2018,20:15,04/10/2018,23:30,S,195,4255,555,0,AI,,,Y,,0,N,0, ,0$307|37|62YO],[63YO,AI,423,BOM,DEL,04/10/2018,20:15,04/10/2018,23:30,S,195,4255,555,0, AI,,,Y,,0,N,0,,0$307|37|63YO],[64YO,AI,777,BOM,DEL,04/10/2018,20:15,04/10/2018,23 :30,S,195,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|64YO],[65YO,AI,1066,BOM,DEL,04/10/ 2018,20:15,04/10/2018,23:30,S,195,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|65YO],[66YO ,AI,635,BOM,DEL,04/10/2018,07:05,04/10/2018,11:10,S,245,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|66YO],[67YO,AI,7019,BOM,DEL,04/10/2018,06:00,04/10/2018,08:00 ,S,120,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|67YO],[68YO,AI,6293,BOM,DEL,04/10/2018, 21:00,04/10/2018,23:30,S,150,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|68YO],[69YO,AI ,9823,BOM,DEL,04/10/2018,01:00,04/10/2018,04:30,S,210,4255,555,0,AI,,,Y,,0,N,0, ,0$307|37|69YO],[6YO,SG,158,BOM,DEL,04/10/2018,18:45,04/10/2018,20:55,C,130,3021,521,0, SG,1, 1C,Y,,500,R,0,,0$307|37|6YO],[70YO,AI,9897,BOM,DEL,04/10/2018,01:00,04/10/2018,04:30 ,S,210,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|70YO],[71YO,AI,9824,BOM,DEL,04/10/2018, 01:00,04/10/2018,05:00,S,240,4255,555,0,AI,,,Y,,0,N,0,,0$307|37|71YO],[72YO,AI ,888,BOM,DEL,04/10/2018,19:00,04/10/2018,21:15,S,135,4255,555,0,AI,2, 3,Y,,0,N,0,,0$307|37|72YO],[73YO,AI,442,BOM,DEL,04/10/2018,15:25,04/10/2018,19:10 ,K,225,12865,965,0,AI,2, 3,Y,,0,N,0,,0$307|37|73YO],[74YO,AI,621,BOM,DEL,04/10/2018,00:20,04/10/2018,02:00 ,M,100,19532,1282,0,AI,2,,Y,,0,N,0,,0$307|37|74YO],[75YO,AI,4012,BOM,DEL,04/10/2018 ,06:00,04/10/2018,08:00,M,120,19532,1282,0,AI,,,Y,,0,N,0,,0$307|37|75YO],[76YO, AI,4015,BOM,DEL,04/10/2018,06:00,04/10/2018,08:00,M,120,19532,1282,0,AI,,,Y,,0,N,0 ,,0$307|37|76YO],[77YO,AI,4017,BOM,DEL,04/10/2018,06:00,04/10/2018,08:00,M,120,19532,1282,0 ,AI,,,Y,,0,N,0,,0$307|37|77YO],[78YO,AI,5353,BOM,DEL,04/10/2018,06:00,04/10/2018, 08:00,M,120,19532,1282,0,AI,,,Y,,0,N,0,,0$307|37|78YO],[79YO,AI,3131,BOM,DEL,04/10 /2018,12:00,04/10/2018,14:00,M,120,19532,1282,0,AI,,,Y,,0,N,0,,0$307|37|79YO],[ 7YO,SG,154,BOM,DEL,04/10/2018,21:30,04/10/2018,23:50,H,140,​​2811,711,0,SG,1, 1C,Y,,500,R,0,,0$307|37|7YO],[80YO,AI,8899,BOM,DEL,04/10/2018,07:30,04/10/2018,09:30 ,M,120,19532,1282,0,AI,,,Y,,0,N,0,,0$307|37|80YO],[81YO,9W,361,BOM,DEL,04/10/2018, 20:45,04/10/2018,22:55,B,130,2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|81YO],[82YO,9W,762,BOM,DEL,04/10/2018,06:00,04/10/2018,08:15 ,B,135,2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|82YO],[83YO,9W,301,BOM,DEL,04/10/2018,07:00,04/10/2018,09:15 ,B,135,2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|83YO],[84YO,9W,355,BOM,DEL,04/10/2018,08:30,04/10/2018,10:45 ,B,135,2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|84YO],[85YO,9W,333,BOM,DEL,04/10/2018,08:00,04/10/2018,10:20 ,B,140,​​2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|85YO],[86YO,9W,331,BOM,DEL,04/10/2018,10:00,04/10/2018,12:20 ,B,140,​​2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|86YO],[87YO,9W,311,BOM,DEL,04/10/2018,18:00,04/10/2018,20:20 ,B,140,​​2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|87YO],[88YO,9W,839,BOM,DEL,04/10/2018,09:00,04/10/2018,11:25 ,B,145,2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|88YO],[89YO,9W,307,BOM,DEL,04/10/2018,11:00,04/10/2018,13:20 ,B,140,​​2549,1729,0,9W,2, 3,Y,,0,N,0,,0$307|37|89YO],[8YO,SG,154,BOM,DEL,04/10/2018,21:30,04/10/2018,23:50 ,C,140,​​3021,521,0,SG,1, 1C,Y,,500,R,0,,0$307|37|8YO],[90YO,9W,351,BOM,DEL,04/10/2018,14:00,04/10/2018,16:10 ,B,130,2633,1733,0,9W,2, 3,Y,,0,N,0,,0$307|37|90YO],[91YO,9W,310,BOM,DEL,04/10/2018,22:35,05/10/2018,00:45 ,B,130,2633,1733,0,9W,2, 3,Y,,0,N,0,,0$307|37|91YO],[92YO,9W,329,BOM,AMD,04/10/2018,05:20,04/10/2018,06:30 ,B,70,2642,1858,1,9W,2, 1,Y,,0,N,0,,0$307|37|92YO],[92YO,9W,687,AMD,DEL,04/10/2018,07:00,04/10/2018,08:40 ,B,100,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|92YO],[93YO,9W,353,BOM,DEL,04/10/2018,17:00,04/10/2018,19:15 ,W,135,3200,1760,0,9W,2, 3,Y,,0,N,0,,0$307|37|93YO],[94YO,9W,2929,BOM,AMD,04/10/2018,02:50,04/10/2018,04:00 ,W,70,3373,1893,1,9W,2, 1,Y,,0,N,0,,0$307|37|94YO],[94YO,9W,687,AMD,DEL,04/10/2018,07:00,04/10/2018,08:40 ,W,100,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|94YO],[95YO,9W,914,BOM,AMD,04/10/2018,16:55,04/10/2018,18:15 ,W,80,3373,1893,1,9W,2, 1,Y,,0,N,0,,0$307|37|95YO],[95YO,9W,687,AMD,DEL,05/10/2018,07:00,05/10/2018,08:40 ,W,100,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|95YO],[96YO,9W,914,BOM,AMD,04/10/2018,16:55,04/10/2018,18:15 ,W,80,3373,1893,1,9W,2, 1,Y,,0,N,0,,0$307|37|96YO],[96YO,9W,655,AMD,DEL,05/10/2018,15:10,05/10/2018,16:50 ,W,100,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|96YO],[97YO,9W,637,BOM,AMD,04/10/2018,21:45,04/10/2018,23:05 ,W,80,3641,1906,1,9W,2, 1,Y,,0,N,0,,0$307|37|97YO],[97YO,9W,687,AMD,DEL,05/10/2018,07:00,05/10/2018,08:40 ,W,100,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|97YO],[98YO,9W,637,BOM,AMD,04/10/2018,21:45,04/10/2018,23:05 ,W,80,3641,1906,1,9W,2, 1,Y,,0,N,0,,0$307|37|98YO],[98YO,9W,655,AMD,DEL,05/10/2018,15:10,05/10/2018,16:50 ,W,100,0,0,0,9W,1, 3,Y,,0,N,0,,0$307|37|98YO],[99YO,9W,339,BOM,DEL,04/10/2018,03:00,04/10/2018,05:05 ,O,125,3998,1798,0,9W,2, 3,Y,,0,N,0,,0$307|37|99YO],[9YO,SG,153,BOM,COK,04/10/2018,09:30,04/10/2018,11:30 ,H,120,3021,921,1,SG,1, 1,Y,,500,R,0,,0$307|37|9YO],[9YO,SG,184,COK,DEL,04/10/2018,13:45,04/10/2018,18:00 ,H,255,0,0,1,SG,1,,Y,,0,R,0,,0$307|37|9YO]]

【问题讨论】:

没关系。您可以使用该方法来转换您的字符串 您的问题不清楚。在您的代码中,您正在为&lt;List&lt;Object&gt;&gt; 创建TypeToken,但稍后您将使用List&lt;String&gt;。此外,您的列表包含字符串列表,而不是 JSONobjects 或字符串。也许尝试使用TypeToken&lt;List&lt;List&lt;String&gt;&gt;&gt; 并确保每个[ 都有其关闭] 无效的 json ,使用正确的 json 在正确的 JSON 字符串中也包含在 '" 中。你负责创建那个 JSON 吗?如果是,请确保添加了这些引号,如果不是,请尝试联系 JSON 提供商并要求进行更改。 在 277 的字符处抛出未终止的数组,不确定这个字符有什么问题 【参考方案1】:

在这里,您将获得 JSONObject,因此您可以将其转换为

JSONArray jsonArray = new JSONArray(readlocationFeed); 

line with following

JSONObject jsnobject = new JSONObject(readlocationFeed);

and after

JSONArray jsonArray = jsnobject.getJSONArray("locations");

for (int i = 0; i < jsonArray.length(); i++) 

    JSONObject explrObject = jsonArray.getJSONObject(i);

这个对象你可以添加到 Arraylist 上。

【讨论】:

不,我正在获取 jsonarray 你可以看到我的字符串【参考方案2】:
This will help you.


JSONArray jsonArrayList = new JSONArray(); 

ArrayList<String> label=new ArrayList<>();

JSONArray jsonArray = new JSONArray(readlocationFeed); 
if(jsonArray.length()>0)

        for(int i=0;i<jsonArray.length();i++)

                JSONArray jsonArrayForValue = new JSONArray(jsonArray.get(i)); 



                if(i==0)

                ////////**********For Label/Header*******///////////

                        for(int j=0;j<jsonArrayForValue.length();j++)

                                label.add(jsonArrayForValue.get(j));
                        

                else

                    JSONObject eachDeatail=new JSONObject();
                    for(int j=0;j<jsonArrayForValue.length();j++)


                        eachDeatail.put(label.get(j),jsonArrayForValue.get(label.get(j)).toString());

                           

                        jsonArrayList.add(eachDeatail);
                

        

【讨论】:

它在这一行抛出错误 JSONArray jsonArray = new JSONArray(readlocationFeed); 字符为 277 的未终止数组这是错误感谢您的回复 请将错误图片发给我。您在哪一行代码中出现错误?

以上是关于如何将 JSON 字符串转换为 JSON 数组列表? [复制]的主要内容,如果未能解决你的问题,请参考以下文章

如何将数组转换成JSON-CSDN论坛

将 JSON 数组转换为 Python 列表

如何将json字符串转换为数组

如何将 JSON 字符串转换为数组

如何使用pyspark将具有多个可能值的Json数组列表转换为数据框中的列

如何使用 PHP 将 JSON 字符串数据转换为数组?