forEach中的JSONArray上的迭代器?

问题描述

我正在尝试读取和解析JSON文件。我已成功阅读它,但在编译错误

import React from "react";
import PropTypes from "prop-types";
import { withStyles } from "@material-ui/core/styles";
import ChromecastButton from "./ChromeCastButton";
import videojs from "video.js";
class VideoCast extends React.PureComponent<any,any> {
  tempWindow: any = window;
  _isMounted = false;
  player = new this.tempWindow.cast.framework.RemotePlayer();
  playerController = new this.tempWindow.cast.framework.RemotePlayerController(
    this.player
  );
  constructor(props) {
    super(props);
    this.state = {
      cast: null,chrome: null,castState: "IDLE"
    };
    this.changePlayingState = this.changePlayingState.bind(this);
    this.changeCastVolume = this.changeCastVolume.bind(this);
    this.seekVideoPosition = this.seekVideoPosition.bind(this);
  }

  componentDidMount() {
    var mediaContents = this.props;
    const context = this.tempWindow.cast.framework.CastContext.getInstance();
    const {
      SESSION_STATE_CHANGED
    } = this.tempWindow.cast.framework.CastContextEventType;
    this.tempWindow.cast.framework.CastContext.getInstance().requestSession();
   
    });
  }

  componentDidUpdate(prevProps) {
    console.log(this.props),prevProps;
    if (this.props["logAction"] !== prevProps["logAction"]) {
      this.changePlayingState(this.props["logAction"]);
    }
    if (this.props["videoVolume"] !== prevProps["videoVolume"]) {
      this.changeCastVolume(this.props["videoVolume"]);
    }
    if (this.props["videoPosition"] !== prevProps["videoPosition"]) {
      this.seekVideoPosition(this.props["videoPosition"]);
    }
    const castSession = this.tempWindow.cast.framework.CastContext.getInstance().getCurrentSession();
    console.log("castSession",castSession);
    if (castSession) {
      if (castSession.l === "SESSION_ENDED") {
        this.props.castState("IDLE");
      }
    }
  }

  sendMediaDataToCast(mediaContents) {
<Some code to cast>
  }

  changePlayingState(action) {
    if (action === "PAUSE" && this.state["castState"] === "WATCHING") {
      this.playerController && this.playerController.playOrPause();
      this.setState({ castState: "STOPPED" });
    }
    if (action === "PLAY" && this.state["castState"] === "STOPPED") {
      this.playerController && this.playerController.playOrPause();
      this.setState({ castState: "WATCHING" });
    }
  }

  changeCastVolume(volume) {
    this.player.volumeLevel = volume;
    this.playerController &&
      this.playerController.setVolumeLevel(this.player.volumeLevel);
  }

  seekVideoPosition(position) {
    console.log(position);
    this.player.canSeek = true;
    this.player.currentTime = position;
    this.playerController && this.playerController.seek();
  }

  render() {
    return <ChromecastButton> </ChromecastButton>;
  }
}
export default VideoCast;

在YouTube视频中,它可以那样工作,但不能在我的计算机上工作。

emptList.forEach(emp -> parseEmpObj((JSONObject) emp));

我得到的错误

public static void main(String[] args)
    {
        JSONParser jsonP = new JSONParser();
        
        try(FileReader reader = new FileReader("C:\\Users\\XXX\\Desktop\\test.json"))
        {
            Object obj = jsonP.parse(reader);
            JSONArray emptList = new JSONArray();
            emptList.add(obj);
            System.out.println(emptList);

            emptList.forEach(emp -> parseEmpObj((JSONObject) emp));
            
            
            
        }
        catch(FileNotFoundException e) {e.printstacktrace(); }
        catch(IOException e) {e.printstacktrace(); }
        catch(ParseException e) {e.printstacktrace(); }
        catch(Exception e) {e.printstacktrace(); }
        
        
    }
    
    private static void parseEmpObj(JSONObject emp)
    {
        JSONObject emptObj = (JSONObject) emp.get("glossary");
        String title = (String) emptObj.get("title");
        
        System.out.print(title);
    }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)