我正在使用React / Typescript,并且切换输入有问题。在页面加载时,我有一个调用服务的函数,以检查切换的json值是否设置为true。在页面加载时,服务被调用,但是json值未正确设置,从而导致页面错误。在save()函数上,我收到此错误消息。如何解决?代码已添加到底部。
TLDR:在切换输入中获取JSON解析错误
message: "JSON parse error: Cannot deserialize instance of `boolean` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `boolean` out of START_OBJECT token↵ at [Source: (PushbackInputStream); line: 1, column: 349] (through reference chain: gov.defense.business.mpp.dto.MentorApplicationChecklistDto["mentorInfoComplete"])"
interface IState {
mentorInfoComplete?: boolean;
}
public componentDidMount = () => {
// this.load();
this.fetchApplication();
}
public render = () => {
<FormControlLabel
control={
<Switch
color="primary"
checked={mentorInfoComplete}
onChange={this.handleMentorInfoChange}
value={mentorInfoComplete}>
Toggle
</Switch>
}
label="NO"
labelPlacement="start"
/>
private fetchApplication = async () => {
const { match } = this.props;
try {
const result = await axios.get(
`/mentorApplication/${match.params.applicationId}/review`
);
const application = _.get(result, `data`);
const mentorInfoComplete = _.get(result, `data`);
this.setState({
application: fromJS(application),
mentorInfoComplete: fromJS(mentorInfoComplete),
});
} catch (err) {
if (process.env.NODE_ENV === "development") {
console.error(err);
}
}
}
}
答案 0 :(得分:0)
编辑2:请忽略此信息。如果可以的话,我会删除。
编辑:我在移动设备上,这是一条评论。
请了解所用语言的名称。这是JavaScript,而不是Java。