-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A JSONObject text must begin with '{' at 1 [character 2 line 1] #1764
Comments
Please give me a solution on it. I am stuck in the JSONObject class. |
This is a basic task of extracting value from json, and you're making a simple thing complicated. Rest-Assured has a way to deal with it using JsonPath class.
|
Thanks for suggesting the simplest way to avoid complex code, I will implement this in my framework. |
@lucas-nguyen-17 could you please give me your opinions on my rest-assured framework (https://github.com/GaganVaidya/APIFramework) Thanks! |
JSONObject jo=new JSONObject(res.toString()); -> This should have been JSONObject jo=new JSONObject(res.asString()); asString instead of toString, if you go back to the tutorial video the instructor would have updated it subsequently. :) I was also stuck in the same. |
|
Code I wrote yesterday:
package APITesting;
import static io.restassured.RestAssured.;
import static io.restassured.matcher.RestAssuredMatchers.;
import static org.hamcrest.Matchers.*;
import org.json.JSONObject;
import org.testng.annotations.Test;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
public class ParsingResponse {
}
File I have used for API testing:
book.json
Response I got in Console:
[RemoteTestNG] detected TestNG version 7.9.0
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
FAILED: APITesting.ParsingResponse.getBookObjet
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
===============================================
Default test
Tests run: 1, Failures: 1, Skips: 0
===============================================
Default suite
Total tests run: 1, Passes: 0, Failures: 1, Skips: 0
The text was updated successfully, but these errors were encountered: