来自REST服务的JSON以错误的名称返回



我目前正在用Netbeans RESTful后端构建一个angularJS/typescript web应用程序。我为供应商设置了typescript接口,如下所示:

interface Vendor {
    vendorno: number,
    name: string,
    address1: string,
    city: string,
    province: string,
    postalcode: string,
    phone: string,
    vendortype: string,
    email: string;
}

当我调用我的rest服务从我的JavaDB中拉回所有的供应商时,它是在一个完全不同的方案下拉回JSON命名,而不是我的接口,为了让我的angular指令工作,我必须引用这个JSON的命名方案,而不是导致事情中断:

[{"vendorAddress":"543 Sycamore Ave","vendorCity":"Toronto","vendorEmail":"bb@depot.ca","vendorName":"Big Bills Depot","vendorNo":1,"vendorPhone":"(999) 555-5555","vendorPostalcode":"N1P1N5","vendorProvince":"ON","vendorType":"Trusted"},
{"vendorAddress":"628 Richmond Street","vendorCity":"London","vendorEmail":"abc@supply.ca","vendorName":"ABC Supply Co.","vendorNo":2,"vendorPhone":"(519) 123-4567","vendorPostalcode":"N6C1L7","vendorProvince":"ON","vendorType":"Trusted"},
{"vendorAddress":"123 Main Boulevard","vendorCity":"Burlington","vendorEmail":"gs@shack.net","vendorName":"Gadget Shack","vendorNo":3,"vendorPhone":"(613) 444-3423","vendorPostalcode":"N3X5S2","vendorProvince":"ON","vendorType":"Unknown"}]

为了在我的局部表中显示这些供应商数据,我必须使用以下angular绑定:

<div class="col-lg-1 col-sm-1 col-xs-1 text-left">{{vend.vendorNo}}</div>
<div class="col-lg-4 col-sm-4 col-xs-4 text-center">{{vend.vendorName}}</div>
<div class="col-lg-3 col-sm-3 col-xs-3 text-center">{{vend.vendorCity}}</div>
<div class="col-lg-3 col-sm-3 col-xs-3 text-center">{{vend.vendorType}}</div>

是否有任何原因,无论是angularJS或我的Java REST服务是自动重命名我返回的JSON有这些属性名称?

是否有任何理由让angularJS或我的Java REST服务自动重命名返回的JSON具有这些属性名称

它没有棱角。可能是Java REST服务。

一个选项是更新接口以匹配服务器返回的内容:

interface Vendor {
    vendorNo: number;
    vendorName: string;
    // so on ...
}

相关内容

  • 没有找到相关文章

最新更新