我正在尝试获取数据"pnfiles";从API映射数据,如果我在post-man中测试API,它将返回以下JSON数据
{
"DataResult": {
"4562": {
"pnData": {
"pnID": "4562",
"userID": "2427",
"storeID": "8",
"supplierID": "1119",
"skuID": "C123-ZA-SI-NE",
"deptID": "",
"categoryID": "",
"note": "Sale",
"priority": "0",
"deviceCreatedTS": "2021-06-22 19:13:35",
"loadedTS": "2021-06-22 19:13:35",
"linkedID": "0",
"dataDate": "2021-06-10",
"channelCode": "18",
"flagID": "7",
"geoLat": "0.00000000",
"geoLong": "0.00000000",
"geoAcc": "0",
"articleDescription": "117 - Citiz & Milk Silver",
"userName": "Christopher Steven Ogle",
"lastSeen": "unread",
"flagDescription": "Sale",
"flagType": "0"
},
"pnfiles": [
{
"fID": "1323",
"pnID": "4562",
"fileName": "IMG_20210620_113839_1.jpg",
"filePath": "../PhotoNoteStore/2021-06-22/4562/1323-IMG_20210620_113839_1.jpg",
"loadedTS": "2021-06-22 19:13:35",
"dateModified": "0000-00-00 00:00:00"
},
{
"fID": "1324",
"pnID": "4562",
"fileName": "IMG_20210620_113822.jpg",
"filePath": "../PhotoNoteStore/2021-06-22/4562/1324-IMG_20210620_113822.jpg",
"loadedTS": "2021-06-22 19:13:35",
"dateModified": "0000-00-00 00:00:00"
}
]
}
}
以下是我试图获取数据并映射数据的服务,或者只是控制台日志。
import { Injectable } from '@angular/core';
import { HttpClient} from '@angular/common/http';
import { environment } from '../../environments/environment';
import { map} from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class GalleryService {
url = environment.url;
constructor(
private http: HttpClient,
) {}
suppliergallery(id) {
return this.http.get(`${this.url}/V2/api/something/?gallery/?supplier=${id}`).pipe(
map(results => {
console.log("result in galleryservice",results);
return results['DataResult']['pnfiles'];
})
);
}
}
如果我获取数据的方式错误,有人能帮我吗?下面的结果来自控制台日志
result in galleryservice
Object { DataResult: {…} }
DataResult:对象{LinkedSuppliers:false,LinkedSupplier计数:1}LinkedSuppliers:false链接的供应商数量:1:对象{…}
这个问题可以关闭,我的错误来自api本身