I have a JSON document where some of the data is multi line string
I have tried the following options and none of them seem to work
e.g.
[
{
"someString" : "A rather long string of English text, an error message \
actually that just keeps going and going -- an error \
message to make the Energizer bunny blush (right through \
those Schwarzenegger shades)! Where was I? Oh yes, \
you've got an error and all the extraneous whitespace is \
just gravy. Have a nice day."
}
]
or
[
{
"someString" : `A rather long string of English text, an error message` +
`actually that just keeps going and going -- an error` +
`message to make the Energizer bunny blush (right through` +
`those Schwarzenegger shades)! Where was I? Oh yes,` +
`you've got an error and all the extraneous whitespace is` +
`just gravy. Have a nice day.`
}
]
or
[
{
"someString" : 'A rather long string of English text, an error message' +
'actually that just keeps going and going -- an error' +
'message to make the Energizer bunny blush (right through' +
'those Schwarzenegger shades)! Where was I? Oh yes,' +
'you've got an error and all the extraneous whitespace is' +
'just gravy. Have a nice day.'
}
]
or this combination with \n as suggested in the comments, but this didn't work either.
[
{
"shortStory": "A rather long string of English text, an error message\n
actually that just keeps going and going -- an error \n
message to make the Energizer bunny blush (right through\n
those Schwarzenegger shades)! Where was I? Oh yes,\n
you've got an error and all the extraneous whitespace is\n
just gravy. Have a nice day."
}
]
And various other combinations. As long as I have new line the code doesn't work.
Here is the code (Angular 2/Javascript) which reads the JSON file
import {
Injectable
} from '@angular/core';
import {
Http,
Headers,
RequestOptions,
Response
} from '@angular/http';
import {
Observable,
Subject
} from 'rxjs/Rx';
import 'rxjs/Rx'; //get everything from Rx
import 'rxjs/add/operator/toPromise';
import {
IArticle
} from './article';
@Injectable()
export class ArticleService {
private jsonFileURL: string = "./assets/data/article-data.json";
constructor(private http: Http) {}
//
getArticles(): Observable < IArticle[] > {
return this.http.get(this.jsonFileURL).map((response: Response) => {
return <IArticle[] > response.json()
}).catch(this.handleError);
}
//
private handleError(errorResponse: Response) {
//console.log(errorResponse.statusText);
return Observable.throw(errorResponse.json().error || "Server error");
}
}