[英]how to extract class name and its properties from json text in angular?
I am new to angular and my internship demands dealing with a lot of json texts and files.我是 angular 的新手,我的实习需要处理大量 json 文本和文件。 The json i'm currently working on looks like this (it represents a class) :
我目前正在处理的 json 看起来像这样(它代表一个类):
{
"name": "client",
"properties": {
"firstName": "string",
"lastName": "string",
"cin": "string",
"age": "int"
}
}
the angular project reads the json text from a textarea therefore the name and the properties can change. angular 项目从 textarea 读取 json 文本,因此名称和属性可以更改。
I need to extract the name of the class and its attributes separetly each time i hit the submit button .每次点击提交按钮时,我都需要分别提取类的名称及其属性。
<form #json="ngForm" >
<textarea placeholder="paste your json file in here" rows="15" cols="150"></textarea>
<button (click)='sendJson(json)'> submit </button>
</form>
Can anyone help me please ?有人可以帮我吗?
Hey I'm not entirely sure what your asking but you can simply use and [(ngModel)]
to track the changes made and save it to a variable.嘿,我不完全确定您的要求,但您可以简单地使用和
[(ngModel)]
来跟踪所做的更改并将其保存到变量中。
.TS .TS
jsonChanges: string;
HTML HTML
<textarea [(ngModel)]="jsonChanges" placeholder="paste your json file in here" rows="15" cols="150"></textarea>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.