gpt4 book ai didi

Java无法解析JSON.stringify生成的JSON

转载 作者:行者123 更新时间:2023-12-01 09:45:29 29 4
gpt4 key购买 nike

从 rc-1 升级到 rc-3 后,JSON.stringfy() 方法在每个值的开头和结尾返回带有 \ 的值:

{
\"perfil\":\"CLIENTE\", ...
}

我应该如何解决这个问题?

代码片段:

post(url, data) {
console.log(JSON.stringify(data));
return Observable.create(observer =>
this.http.post(this.restConfig.baseUrl + url, JSON.stringify(data), {
headers: this.getDefaultHeaders()
}).subscribe(
data => this.next(observer, data)
, err => {
console.log(err);
if (err.status === 401) {
this.redirectAuth();
}
observer.error(err);
}
)
);
}

我的 Java RESTful 服务无法解析输出:

Unexpected token (VALUE_STRING), expected FIELD_NAME: missing property 'perfil' that is to contain type id  (for class br.com.inbit.medipop.model.entities.impl.Cliente) at [Source: java.io.ByteArrayInputStream@79f844cf; line: 1, column: 1]

客户类别:

@Table
@Entity
@DiscriminatorValue("CLIENTE")
public class Cliente extends Usuario {

}

乌苏里奥级:

@Table
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "perfil", discriminatorType = DiscriminatorType.STRING)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.PROPERTY, property = "perfil")
@JsonSubTypes({
@JsonSubTypes.Type(value = Administrador.class, name = "ADMIN"),
@JsonSubTypes.Type(value = Colaborador.class, name = "COLABORADOR"),
@JsonSubTypes.Type(value = Parceiro.class, name = "PARCEIRO"),
@JsonSubTypes.Type(value = Cliente.class, name = "CLIENTE"),
@JsonSubTypes.Type(value = Dependente.class, name = "DEPENDENTE")
})
public abstract class Usuario {

@NotNull
@Enumerated(EnumType.STRING)
@Column(insertable = false, updatable = false)
protected PerfilUsuario perfil;

...
}

stringfy之前的数据:

{"perfil":"CLIENTE","pessoa":{"tipo":"FISICA","sexo":"MASCULINO","nome":"Marcos Kichel","cpf":"911.111.064-36","rg":"1234"},"dependentes":[],"email":"anackichel@gmail.com"}

最佳答案

您似乎正在对已经字符串化的东西进行字符串化。取出 JSON.stringify() 就可以开始了。

关于Java无法解析JSON.stringify生成的JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38083780/

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