i'm having this issue trying to send JSON to my REST API. I don't think it's an issue with the method itself because it seems to run fine when I call the endpoint in postman. When I call the endpoint using HttpClient, it results in the error below.
我有这个问题试图将JSON发送到我的REST API。我不认为这是方法本身的问题,因为当我在postman中调用端点时它似乎运行正常。当我使用HttpClient调用端点时,会导致下面的错误。
Unterminated string. Expected delimiter: ". Path 'StaticPasses', line 1, position 178.
Here's my JSON:
这是我的JSON:
{"Id":0,"Email":"teststaff@test.com","Name":"TestStaff","Password":"Password","SchoolId":3,"StaticPasses":"[{\"QrCode\":\"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://hallpass.azurewebsites.net/api/pass/getstaticpass/0/3/0\",\"Id\":0,\"Staff\":0,\"Student\":-1,\"ExpirationTime\":\"00:00:00\",\"CreationTime\":\"02:37:28.2114320\",\"Destination\":\"Destination\",\"ShareCode\":\"0\"},{\"QrCode\":\"https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=http://hallpass.azurewebsites.net/api/pass/getstaticpass/1/3/0\",\"Id\":0,\"Staff\":0,\"Student\":-1,\"ExpirationTime\":\"00:00:00\",\"CreationTime\":\"02:38:01.8744350\",\"Destination\":\"Destination\",\"ShareCode\":\"1\"}]"}
Again, the JSON seems to work perfectly in Postman, but doesn't work in my code.
同样,JSON似乎在Postman中完美运行,但在我的代码中不起作用。
Here's the call to the server:
这是对服务器的调用:
string staffJson = JsonConvert.SerializeObject(staff);
var response = await client.GetAsync("schools/updatestaff?staff=" + staffJson);
If anyone can tell me what is wrong with the JSON or the call, that would be great. Thanks!
如果有人能告诉我JSON或通话有什么问题,那就太好了。谢谢!
1 个解决方案
#1
0
Apparently, Newtonsoft.Json doesn't like when you contain a link in a string and throws out that error. I solved the problem by just shortening my links to just hold the information for their endpoint.
显然,当你在字符串中包含一个链接并抛出该错误时,Newtonsoft.Json不喜欢。我通过缩短链接来解决问题,只需保存端点的信息。
#1
0
Apparently, Newtonsoft.Json doesn't like when you contain a link in a string and throws out that error. I solved the problem by just shortening my links to just hold the information for their endpoint.
显然,当你在字符串中包含一个链接并抛出该错误时,Newtonsoft.Json不喜欢。我通过缩短链接来解决问题,只需保存端点的信息。