-1

I'm working on a school project where we have to create an app. One page contains true/false questions that the professor provides and the students can answer. The page is done, except for the http request to get the questions and answer keys. I'm currently mocking the server with postmann. A request to the provided link from postmann works.

However, I always get JSON parsing erros...

This is of the JSON Strings I tried to used

{
„question“ : „what is 2x2?“ ,
„answerKey“ : true
}

And this is the error message I get:

SyntaxError: "JSON.parse: expected property name or '}' at line 2 column 1 of the JSON data"

The Question class has two attributes:

answerKey: boolean;

and

question: string

And below you can see my http.get function and the function that calls the get function

public getAllQuestions(): Observable<Question[]> {
        return this.http.get<Question[]>(this.baseurl.concat('quiz'));
    }

public pullQuestionFromBackend(): void {
        this.submitQuizService.getAllQuestions().subscribe((question: Question[]) => {
            this.questionList = <Question[]> question;
        });
    }
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Yoey
  • 408
  • 1
  • 4
  • 16

1 Answers1

1

That's not valid JSON format.

is different than "

Try with

{
"question" : "what is 2x2?" ,
"answerKey" : true
}
ztadic91
  • 2,774
  • 1
  • 15
  • 21
  • Okay that fixed my parsing error, thanks for that! However, now I found this less descriptive error: Http failure response for (unknown url): 0 Unknown Error – Yoey Jan 28 '19 at 22:05
  • for that part have a look at an already existing [question](https://stackoverflow.com/questions/47180634/i-get-http-failure-response-for-unknown-url-0-unknown-error-instead-of-actu) – ztadic91 Jan 28 '19 at 22:10