이상한 꽤 형식화 된 방식으로 내 JSON 인쇄하려면 노력하고있어 내 JSON \
함께 반환하고 꽤 인쇄되지 않는 유지합니다.각도 2 prettify JSON 파이프 필터
나는이 솔루션을 plnkr에서 사용할 수 있지만 실제 응용 프로그램에서는 사용할 수 없습니다. 아래 이미지는 plnkr에있는 것과 비슷한 JSON 인쇄물입니다.
왜 이런 일이 일어나고있는가요?
Plnkr 샘플 : https://plnkr.co/edit/ZqOXS30XPTu9ponWFdgZ?p=preview
코드 파이프 :
@Pipe({
name: 'prettyprint'
})
export class PrettyPrintPipe {
transform(val) {
if(typeof(val) == "undefined" || typeof(val) == null) return ''; //check value before process it.
return JSON.stringify(val, null, 2)
.replace(/ /g, ' ')
.replace(/\\n/g, '<br>');
}
}
JS 개체, 나는 concat
내가 할 수 있도록 두 개체를 JSON.stingify
또는 부모 내부의 childObj
를 추가해야합니다.
var parentJSONObj = JSON.stringify(object)
var childObj = JSON.stringify(object) // in a diferent schema
this.output = parentJSONObj.replace(replaceObj, childObj) // and need to replace a property inside childObj
정도로 this.output
파이프 필터 슬래시 추가 제공 추가 내가 이미 JSON 문자열 생각 최종 JSON 구조이다. 내가 JSON.parse(this.output)
를하려고하면 그것은 나에게 CSS 솔루션을 Unexpected token o in JSON at position 214
같은, 내가 plnkr 업데이트와'
대체 기능이 필요한 이유는 무엇입니까? – Bazinga
당신의 플렁커가 현재 작동 중 https://plnkr.co/edit/wdUHPHk6l5h8vY2viddj?p=preview – Bazinga