控制字符错误,可能编码不正确
Control character error, possibly incorrectly encoded
我正在开发代号为 one 链接到 symfony 4 的移动应用程序,用户可以参加我有此表的视频竞赛我所有的数据都是正确的,但它向我显示了这个错误:控制字符错误,可能编码不正确我希望有人能帮助我谢谢。
这是我在 symfony4 上的功能:
*
*
* @Route("/api/competition/participate/", name="api_competitions_participate")
* @param Request $request
* @return Response
* @throws Exception
*/
public function participateAction(Request $request)
{
$r=$request->query->get('video');
$encoders = [new XmlEncoder(), new JsonEncoder()];
$normalizers = [new ObjectNormalizer()];
$serializer = new Serializer($normalizers, $encoders);
$video = $serializer->deserialize($r, Video::class, 'json');
$u=$this->getDoctrine()->getRepository(Users::class)->find($video->getOwner()['id']);
$video->setOwner($u);
$video->setPublishdate(new \DateTime('now'));
dump($video);
$r2=$request->query->get('participation');
$participation= $serializer->deserialize($r2, Participation::class, 'json');
$c=$this->getDoctrine()->getRepository(Concour::class)->find($participation->getConcour()['id']);
$participation->setUser($u);
$participation->setConcour($c);
$participation->setVideo($video);
$participation->setDateParticipation($video->getPublishdate());
dump($participation);
$em = $this->getDoctrine()->getManager();
$em->persist($video);
$em->persist($participation);
$em->flush();
dump($r);
return new JsonResponse();
}
这是代号one
上的函数
public void participate(Video v, Participation cp) {
Gson gson = new Gson();
String json = gson.toJson(v);
String json2 = gson.toJson(cp);
String url = Statics.BASE_URL + "/api/competition/participate/?video=" + json + "&participation=" + json2;
con.setUrl(url);
con.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
String str = new String(con.getResponseData());
System.out.println(str);
Dialog.show("Confirmation", "Your Video has been successfully added", "Ok", null);
con.removeResponseListener(this);
}
});
NetworkManager.getInstance().addToQueueAndWait(con);
我不熟悉 Symfony,所以我不确定这是否是正确的答案。此外,您在 get 查询中传递 JSON 的方法被大多数人认为是错误的形式。通常 JSON 将在 POST
方法主体中传递以进行 REST 调用。
要正确编码,请使用:
String url = Statics.BASE_URL + "/api/competition/participate/"
con.setUrl(url);
con.addArgument("video", json);
con.addArgument("participation", json2);
还要确保 ConnectionRequest
是用 false
构造的,以表明这是一个 GET
操作而不是 POST
。
我正在开发代号为 one 链接到 symfony 4 的移动应用程序,用户可以参加我有此表的视频竞赛我所有的数据都是正确的,但它向我显示了这个错误:控制字符错误,可能编码不正确我希望有人能帮助我谢谢。 这是我在 symfony4 上的功能:
*
*
* @Route("/api/competition/participate/", name="api_competitions_participate")
* @param Request $request
* @return Response
* @throws Exception
*/
public function participateAction(Request $request)
{
$r=$request->query->get('video');
$encoders = [new XmlEncoder(), new JsonEncoder()];
$normalizers = [new ObjectNormalizer()];
$serializer = new Serializer($normalizers, $encoders);
$video = $serializer->deserialize($r, Video::class, 'json');
$u=$this->getDoctrine()->getRepository(Users::class)->find($video->getOwner()['id']);
$video->setOwner($u);
$video->setPublishdate(new \DateTime('now'));
dump($video);
$r2=$request->query->get('participation');
$participation= $serializer->deserialize($r2, Participation::class, 'json');
$c=$this->getDoctrine()->getRepository(Concour::class)->find($participation->getConcour()['id']);
$participation->setUser($u);
$participation->setConcour($c);
$participation->setVideo($video);
$participation->setDateParticipation($video->getPublishdate());
dump($participation);
$em = $this->getDoctrine()->getManager();
$em->persist($video);
$em->persist($participation);
$em->flush();
dump($r);
return new JsonResponse();
}
这是代号one
上的函数 public void participate(Video v, Participation cp) {
Gson gson = new Gson();
String json = gson.toJson(v);
String json2 = gson.toJson(cp);
String url = Statics.BASE_URL + "/api/competition/participate/?video=" + json + "&participation=" + json2;
con.setUrl(url);
con.addResponseListener(new ActionListener<NetworkEvent>() {
@Override
public void actionPerformed(NetworkEvent evt) {
String str = new String(con.getResponseData());
System.out.println(str);
Dialog.show("Confirmation", "Your Video has been successfully added", "Ok", null);
con.removeResponseListener(this);
}
});
NetworkManager.getInstance().addToQueueAndWait(con);
我不熟悉 Symfony,所以我不确定这是否是正确的答案。此外,您在 get 查询中传递 JSON 的方法被大多数人认为是错误的形式。通常 JSON 将在 POST
方法主体中传递以进行 REST 调用。
要正确编码,请使用:
String url = Statics.BASE_URL + "/api/competition/participate/"
con.setUrl(url);
con.addArgument("video", json);
con.addArgument("participation", json2);
还要确保 ConnectionRequest
是用 false
构造的,以表明这是一个 GET
操作而不是 POST
。