Closed navjot50 closed 2 years ago
interesting, I agree this could be handled by the library. What would be your approach?
My approach would be:
{\"id\":.+}
. I think this regex is enough and a more strict recursive regex for json syntax is not required because wordpress rest api responses are supposed to start with id as the first property in json.WPUnexpectedException
.JsonConvert.DeserializeObject
is being used in HttpHelper
and ThreadedCommentsHelper
.The regex will come into play only when the response has markup pollution.
sounds like a plan to me. are there instances where an array is returned from the API?
Correct. Array is returned in case of multiple entries. So, that case also needs to be taken care of and in that case the response starts with [
.
Merged and part of the first 2.0-alpha release
I tried to upload an image using WordpressPCL and I got a Newtonsoft.Json.JsonReaderException with a message "Unexpected character encountered while parsing value: <. Path '', line 0, position 0.". I found out that the image was successfully uploaded on the wordpress server but not assigned to
MediaItem item = await client.Media.Create(imageStream, "img.jpg");
, instead there was the above exception.Further investigating, I found out that the json response from the wordpress server was preceded by PHP warnings markup. A cut down version of the response looked like:
So, basically the library was expecting no markup in front of json. I found out that this markup comes up only when
WP_DEBUG_DISPLAY
is set to true. In development phase this constant is set to true most of the times. So, the library should handle this because the image is uploaded on the server but the json for it could not be deserialized by the library.I can give a PR to fix this issue.