【发布时间】:2017-01-16 15:22:53
【问题描述】:
我正在尝试使用导入功能,用户可以导入原始 JSON,然后将其发布到服务器。
例如,如果用户粘贴此 json:
{
"name": "testing",
"design": [
{
"name": "test",
"comments": [
{
"short": "123",
"long": "1234567890"
}
],
"maxMark": 0
}
]
}
然后我希望所有这些都发送到服务器。 但不确定处理此类任务的最佳方式。
现在我有一个简单的表格:
<modal #importModal [keyboard]="false" [backdrop]="'static'">
<modal-header [show-close]="false">
<h4 class="modal-title">Importing a module</h4>
</modal-header>
<modal-body>
<form name="importForm" [ngFormModel]="importForm" (ngSubmit)="importForm.valid" novalidate>
<textarea class="form-control" rows="20" #data='ngForm' [ngFormControl]="importForm.controls['data']"></textarea>
</form>
<pre>{{importForm.value | json }}</pre>
</modal-body>
<modal-footer>
<button type="button" class="btn btn-danger" (click)="importModal.dismiss()"><i class="fa fa-close"></i> Close</button>
<button type="button" class="btn btn-primary" type="submit" [disabled]="!importForm.valid" (click)="importModal.dismiss() && submitImport(importForm.value)"><i class="fa fa-floppy-o"></i> Submit</button>
</modal-footer>
</modal>
但是表单的值显示为:
"data": "{\n \"name\": \"testing\",\n \"design\": [\n {\n \"name\": \"test\",\n \"comments\": [\n {\n \"short\": \"123\",\n \"long\": \"1234567890\"\n }\n ],\n \"maxMark\": 0\n }\n ]\n}"
我必须对其进行字符串化然后剥离它吗?将其转换回 JSON 的最佳方法是什么?
【问题讨论】:
标签: angularjs json angular typescript