gpt4 book ai didi

Java错误扫描JSONObject程序使用扫描仪无限扫描

转载 作者:行者123 更新时间:2023-12-02 11:22:42 25 4
gpt4 key购买 nike

我在编写此程序时遇到此错误,我只想通过扫描仪传递到 JSONobject 并打印 json 对象

但是扫描仪进入无限循环

package com.readvalues.main;

import java.util.Scanner;
import net.sf.json.JSONObject;

public class ReadValues
{
public static void main(String[] args)
{
String x="";
try
{
System.out.println("Enter the data");
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext())
{
x = x + scanner.next();
}

JSONObject jsonObject = JSONObject.fromObject(x);
System.out.println(jsonObject);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

在终端

Enter the data
{"ExecutiveGoal":
{"EMPLID":"100020","GOAL_ID":"GOAL-3-98372","GOAL":"Conduct EPC Contract Kaizen","DUE_DATE":"07/01/2018","STATUS":"On Track or Complete (Green)","CATEGORY":"Operational Goal","SUPPORTS_ORG_GOAL":"","COMPLETED_ON":"06/30/2018","CREATED_BY":"Mark Hensley","CREATED_ON":"03/01/2018","LAST_UPDATED_BY":"Mark Hensley","LAST_UPDATED_ON":"03/01/2018"
},
"ExecutiveGoal":
{"EMPLID":"100020","GOAL_ID":"GOAL-3-98373","GOAL":"Exit 2018 with minimum 5 negotiators trained and capable in O&M, MSAs, EPCs, and MIPSAs. At least 2 negotiators capable in PPAs.","DUE_DATE":"12/31/2018","STATUS":"On Track or Complete (Green)","CATEGORY":"People Leader Goal","SUPPORTS_ORG_GOAL":"","COMPLETED_ON":"","CREATED_BY":"Mark Hensley","CREATED_ON":"03/01/2018","LAST_UPDATED_BY":"Mark Hensley","LAST_UPDATED_ON":"03/01/2018"
}
}
//INFINITE LOOP SCANNING

我已经尽力了

最佳答案

扫描仪正在等待内部...Scanner.nextLine() 会有帮助。

关于Java错误扫描JSONObject程序使用扫描仪无限扫描,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49810601/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com