小编Sha*_*ald的帖子

针对JSON Schema C#验证JSON

有没有办法根据该结构的JSON模式验证JSON结构?我看了,发现JSON.Net验证,但这不符合我的要求.

JSON.net做:

JsonSchema schema = JsonSchema.Parse(@"{
  'type': 'object',
  'properties': {
    'name': {'type':'string'},
    'hobbies': {'type': 'array'}
  }
}");

JObject person = JObject.Parse(@"{
  'name': 'James',
  'hobbies': ['.NET', 'LOLCATS']
}");

bool valid = person.IsValid(schema);
// true
Run Code Online (Sandbox Code Playgroud)

这证实为真.

JsonSchema schema = JsonSchema.Parse(@"{
  'type': 'object',
  'properties': {
    'name': {'type':'string'},
    'hobbies': {'type': 'array'}
  }
}");

JObject person = JObject.Parse(@"{
  'surname': 2,
  'hobbies': ['.NET', 'LOLCATS']
}");

bool valid = person.IsValid(schema);
Run Code Online (Sandbox Code Playgroud)

这也证实了这一点

JsonSchema schema = JsonSchema.Parse(@"{
  'type': 'object',
  'properties': {
    'name': {'type':'string'},
    'hobbies': {'type': 'array'}
  }
}"); …
Run Code Online (Sandbox Code Playgroud)

c# validation json jsonschema

16
推荐指数
1
解决办法
3万
查看次数

使用angular2为innerHtml渲染CSS

我试图使用innerHTML和我从SQL获得的html + css字符串呈现HTML模板.

模板字符串示例:

<html xmlns="http://www.w3.org/1999/xhtml"> <head><title>Template Name</title><style type="text/css"> p{ color:red; }</style> </head> <body> <h1>#headding#</h1> <p style="color:red;">#paragraph#</p><a href="#url#">#urltext#</a> </body> </html>
Run Code Online (Sandbox Code Playgroud)

现在它渲染HTML很好但看起来它会删除样式标记并只在其中呈现文本.

渲染示例:

在此输入图像描述

HTML渲染部分:

<div [innerHtml]="templateBody">
</div>
Run Code Online (Sandbox Code Playgroud)

Home.component.ts部分:

@Component({
    selector: "home",
    templateUrl: `client/modules/home/home.component.html`,
    encapsulation: ViewEncapsulation.Emulated
})
export class HomeComponent implements OnInit{
    templateBody: string;
.....other code
}
Run Code Online (Sandbox Code Playgroud)

我已经尝试了封装:ViewEncapsulation.Emulated/None等,尝试了内联CSS,我尝试附加:host >>> inf标签.他们都呈现相同.

有什么建议?

innerhtml angular

7
推荐指数
1
解决办法
6962
查看次数

标签 统计

angular ×1

c# ×1

innerhtml ×1

json ×1

jsonschema ×1

validation ×1