Newtonsoft.Json.JsonReaderException occurred
nskiro opened this issue · 4 comments
Hello Zaczero,
Thank you for nice library, but I got an error. You can see my code below:
var captcha = new _2Captcha(<my_API_key>);
KeyValuePair<string, string>[] options = new KeyValuePair<string, string>[]
{
// I have to add this because my language isn't English
new KeyValuePair<string, string>("textinstructions","Select icons in the order required")
};
var clickCaptcha = await captcha.SolveClickCaptcha(ImageToBase64String("captcha.png"), FileType.Png, "TASK", options);
The captcha has been solved (I checked in my dashboard at 2captcha.com). But Newtonsoft.Json.JsonReaderException occurred. Error message is
{"Unexpected character encountered while parsing value: [. Path 'request', line 1, position 23."}
I see in VS , the return object is {Success: false, Response: null}
Please help me! Thank you very much.
I think it may have to do something with a KeyValuePair array being used instead of a Dictionary.
I have had some problems with that in the past. A fix should come really soon. Thanks for reporting!
I think the problem is occurred when parsing final response from 2captcha. In document of 2captcha, they write:
By default answers are returned as plain text like: OK|Your answer. But answer can also be returned as JSON {"status":1,"request":"TEXT"} if json parameter is used.
You can see the request property in JSON response, it does appear in error message.
Edit: I remove KeyValuePair array and this exception still occurred
Hello Zaczero,
Most likely the problem occurs when the final return string contains an array of coordinates, but the type of request variable is string.
This is return object:
{
"status": 1,
"request": [
{
"x": "150",
"y": "114"
},
{
"x": "126",
"y": "183"
},
{
"x": "86",
"y": "191"
},
{
"x": "55",
"y": "69"
}
]
}
Fixed in the latest release 1.10
After retrieving the result and checking for .Success
you may now use one of the following properties:
.ResponseCoordinates
which will return an array of X-Y coordinates (it's a predefined structure/best for your use case).ResponseJson
which will return an unparsed JSON string (if you want to process it by yourself).ResponseObject
which will return aJToken
which can be used to easily parse data to any format you wish (check out.ToObject<T>()
method)