小编ano*_*oop的帖子

JSON反序列化,错误:值类型为null,如何知道导致错误的确切属性?

在我的C#代码中,我试图反序列化具有100多个属性(复杂,原始,派生的)的JSON,但出现错误Cannot convert null to a value type.

尽管我最终通过手动故障排除知道了哪个属性导致了问题。

但是,有什么方法可以让我简单地知道JSON或Result_TYPE property or properties(一次完成),从而导致此问题?

我尝试调查detail windowException,但我只能知道datatype。就我而言,它null试图转换为boolean。,但找不到属性名称。

例如:我的JSON

  {
      "customerData": 
      {
        //... other json data

        "someClass":{
            "someClassProp1":"prop1Value",
            "someClassProp2":"prop2Value"
           },
        "isExistData":null,
        "someOtherClass":null

        //... some other json data
      }
  }
Run Code Online (Sandbox Code Playgroud)

并且Result_TYPE为:

Public class CustomerData
{
    // Other properties

    public SomeClass someClass:
    public bool isExistData;    
    public SomeOtherClass someOtherClass:

    // some Other properties
}
Run Code Online (Sandbox Code Playgroud)

我正在使用 JavaScriptSerializer().Deserialize<T>(jsonString);

在上面的示例中:我将如何知道该属性isExistData将导致反序列化错误,因为属性类型为boolean,传入数据为null。[当然除了手动调试,因为可能有100多个属性]

任何人,如果知道找到确切财产的更好方法?

.net c# javascriptserializer json-deserialization

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

离子角对于ng-bind有不同的作用,{{}}不知道为什么?

我正在尝试使用其空白模板实现离子UI.这是我的home.ts文件,位于/ pages/home /文件夹中.

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
  items = [
   {id: 1,text:"first"},
   {id: 2,text:"second"},
   {id: 3,text:"third"},
   {id: 4,text:"forth"}
];
  constructor(public navCtrl: NavController) {}
  itemSelected(item){   
    item.text+=" Checked";
    alert(item.text);
  }
}
Run Code Online (Sandbox Code Playgroud)

这是home.html文件.

<ion-header>
  <ion-navbar>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>
<ion-content padding>
  <ion-list inset>    
  <button ion-item *ngFor="let item of items" (click)="itemSelected(item)">
    <p>{{ item.id }} <span ng-bind="item.text"></span></p>    
  </button>
</ion-list>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

如果我使用{{item.text}}而不是 比值得到显示,但我想知道为什么ng-bind不起作用,因为ng-bind的渲染频率高于{{}}.

javascript typescript ionic-framework angular

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

@input和@output装饰器改变事件

通过@input\@output装饰的一些代码,我发现了不同的行为.

在下面的代码中,组件通过装饰器counter从父组件获取其值,并app通过@input装饰器发出更改@output.

我的问题 :

  1. 当我在文本框中手动输入值时,为什么更改事件是调用.?,而我this.change.emit(this.count);只在Increment\Decrement函数内部定义.?

  2. 当我通过Increment\Decrement按钮进行更改时,我在app组件(父级)中获得了正确的更改值,但是当我手动键入值时,我得到的[object Event]不是键入的数字.为什么这样 ?

代码如下Plunker在这里.

计数器组件:

import { Component, Input, Output, EventEmitter } from '@angular/core';

@Component({
  selector: 'counter',
  template: `
    <div class="counter">
      <button (click)="decrement()">
        Decrement
      </button>
        <input type="text" [(ngModel)]="count">
      <button (click)="increment()">
        Increment
      </button>
    </div>
  `
export class CounterComponent {  
  @Input()
  count: number = 0;

  @Output()
  change: EventEmitter<number> = new EventEmitter<number>();

  increment() {
    this.count++; …
Run Code Online (Sandbox Code Playgroud)

angular

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

错误错误:没有JwtHelper的提供者

我是Angular2的新手,我正在使用jwthelper来编码jwt令牌并提取细节.

import { Injectable } from '@angular/core';

import { JwtHelper } from 'angular2-jwt';

@Injectable()
export class SessionService {

  constructor(private jwtHelper: JwtHelper){}

  getUser(){
    var token = JSON.parse(localStorage.getItem('currentUser'));
    return this.jwtHelper.decodeToken(token.token);
  }
}
Run Code Online (Sandbox Code Playgroud)

找不到以下错误的解决方案,并告诉我这里有什么不对.

错误错误:没有JwtHelper的提供者!

authentication jwt web angular

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