带有四个列表的Zip功能

时间:2019-05-29 08:14:02

标签: python json

当我对从json提取的四个列表使用zip时,它抱怨第四个列表不可迭代,无论我的哪个列表是第四个。可以很好地处理三个列表。

    sta= json.loads(aircraft.stations).get('Stations');
    stations = zip(sta.get('name'),sta.get('short'),sta.get('arm'),sta.get('type'));
{
  "Stations": {
    "name": [
      "Aircraft",
      "Pilots",
      "Seat 3",
      "Seat 4",
      "Seat 5",
      "Seat 6",
      "Seat 7",
      "Seat 8",
      "Fwd.Baggage",
      "Rear Baggage",
      "Inb. Fuel Tank",
      "Outb. Fuel Tank"
    ],
    "values": [
      "127,1",
      "119,0",
      "159,0",
      "159,0",
      "198,0",
      "198,0",
      "229,0",
      "242,0",
      "43,0",
      "255,0",
      "126,8",
      "148,0"
    ],
    "short": [
      "ac",
      "pilot",
      "s3",
      "s4",
      "s5",
      "s6",
      "s7",
      "s8",
      "fwdb",
      "rearb",
      "inbf",
      "outbf"
    ],
    "type": [
      "ac",
      "crew",
      "pax",
      "pax",
      "pax",
      "pax",
      "pax",
      "pax",
      "bag",
      "bag",
      "fuel",
      "fuel"
    ]
  }
}
  
    
      

zip(s.get('type'),s.get('short'),s.get('name'),s.get('arm'))       追溯(最近一次通话):         文件“”,第1行,位于       TypeError:zip参数4必须支持迭代

    
  

2 个答案:

答案 0 :(得分:0)

您的json没有“ arm”字段

答案 1 :(得分:0)

您似乎正在尝试获取不可用的密钥 27 May 2019 18:12:37 ERROR [taskExecutor-13] synchronizer.SynchronizerPostProcessUtil:162 - Batch Process Call Errored - DB is not updated org.springframework.orm.hibernate5.HibernateJdbcException: JDBC exception on Hibernate data access: SQLException for SQL [ select count(1) from kwt.Error_BatchUpdate(?,?,?) ]; SQL state [null]; error code [0]; could not prepare statement; nested exception is org.hibernate.exception.GenericJDBCException: could not prepare statement at org.springframework.orm.hibernate5.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:248) at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:368) at org.springframework.orm.hibernate5.HibernateTemplate.execute(HibernateTemplate.java:315) at com.company123.db.dao.common.HibernateDao.callStoredProcedureWithParameters(HibernateDao.java:947) at com.company123.db.dao.common.HibernateDao.callOpenXmlBatchProcessingWithParameters(HibernateDao.java:927) at com.company123.synchronizer.SynchronizerPostProcessUtil.executeBatchItems(SynchronizerPostProcessUtil.java:156) at com.company123.synchronizer.SynchronizerPostProcessUtil.processPostProcessItems(SynchronizerPostProcessUtil.java:76) at com.company123.synchronizer.AbstractSubAccountSynchronizer.createSubAccount(AbstractSubAccountSynchronizer.java:51) at com.company123.synchronizer.AbstractSubAccountSynchronizer.createSubAccount(AbstractSubAccountSynchronizer.java:23) at com.company123.synchronizer.SESynchronizer.syncSubAccount(SESynchronizer.java:990) at com.company123.synchronizer.SESynchronizer.syncLocalToSE(SESynchronizer.java:332) at com.company123.lifecycle.mb.LifeCycleRunnable.runMBLifeCycle(LifeCycleRunnable.java:188) at com.company123.lifecycle.mb.LifeCycleRunnable.run(LifeCycleRunnable.java:113) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: org.hibernate.exception.GenericJDBCException: could not prepare statement at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:181) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:147) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1985) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1915) at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1893) at org.hibernate.loader.Loader.doQuery(Loader.java:938) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:341) at org.hibernate.loader.Loader.doList(Loader.java:2692) at org.hibernate.loader.Loader.doList(Loader.java:2675) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2507) at org.hibernate.loader.Loader.list(Loader.java:2502) at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:335) at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:2200) at org.hibernate.internal.AbstractSharedSessionContract.list(AbstractSharedSessionContract.java:1016) at org.hibernate.query.internal.NativeQueryImpl.doList(NativeQueryImpl.java:152) at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1414) at org.hibernate.query.internal.AbstractProducedQuery.uniqueResult(AbstractProducedQuery.java:1457) at com.company123.db.dao.common.HibernateDao$19.doInHibernate(HibernateDao.java:971) at org.springframework.orm.hibernate5.HibernateTemplate.doExecute(HibernateTemplate.java:361) ... 14 more Caused by: java.sql.SQLException: Connection org.postgresql.jdbc.PgConnection@25d46a62 is closed. at org.apache.commons.dbcp2.DelegatingConnection.checkOpen(DelegatingConnection.java:594) at org.apache.commons.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:289) at org.apache.commons.dbcp2.DelegatingConnection.prepareStatement(DelegatingConnection.java:292) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:145) at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:171) ... 32 more 。 因此,它不适合迭代。

能否请您尝试下面的代码,看看它是否有效:

arm