【发布时间】:2019-06-04 09:56:27
【问题描述】:
我收到了来自 postgres DB 的响应,其中包含数组周围的 qoutes
images: "[{"image":"https://dw901jjvwj0lk.cloudfront.net/smart-address/image/gift certificate/afa9b56f-ddb4-4ae5-b72b-afae20129ea4/gift certificate/IMG_5076.JPG"}]"
info: "[{"balance_owo":0,"balance_btc":0,"btc_address":0,"btc_qr":null,"price_usd":25,"details":"use this gift certificate at sweet sosumba on Georgia and Park NW","quantity":500,"quantity_left":null}]"
引号阻止 *ngFor 意识到这是一个数组
我尝试使用 jsonb 返回 = 从数据库中删除引号,但不起作用。
$query=$dbh->prepare("SELECT *, earth_distance(ll_to_earth($user_lat,$user_lng), ll_to_earth(lat, lng)) as local_distance
FROM tribe.smart_address
WHERE earth_box(ll_to_earth($user_lat,$user_lng), $fence) @> ll_to_earth(lat, lng) AND active=:one
ORDER by date_created DESC");
$query->bindValue(':one', 1);
$query->execute();
$gifts = $query -> fetchAll()
我也试过了
[src]="removeQuotes(data.images)"
[src]="data.images[0].image"
没有任何作用...消毒也不起作用...请问我该如何解决
这是从数据库中获取数据的角度代码
this.$local.gift_start(this.user_token, this.user_id,
this.user_lat, this.user_lng, this.type)
.then((jordi: any) => {
if (jordi.success) {
this.Dsmart = jordi.payload[0]
}
)
从服务返回承诺
return new Promise(resolve => {
this.http.post('https://owo.world/app/gift/start', DATA, httpOptions)
.subscribe(data => {
resolve(data);
}, err => {
console.log(err);
});
});
首页
<div class="card current_progress" *ngFor="let data of
Dsmart; let i = index">
<a [href]="data[i].images"> <img class="img-fluid img-raised"
[src]="data[i].images[0].image" alt=""> </a>
它不能。获取图像,因为它是作为字符串返回的......需要删除引号才能使其工作
【问题讨论】:
-
不是 JSON 吗?
JSON.parse(data) -
它是 JSON... JSON 解析在 JSON 中的位置 1 返回 Unexpected token o 它在 php 端编码 echo json_encode($data,true);
-
能否提供将json字符串返回到angular的代码?
-
我更新了代码
标签: arrays angular postgresql multidimensional-array