arrays - 从数组值中删除引号
问题描述
我有一个来自 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>
它不能。获取图像,因为它作为字符串返回...需要删除引号才能使其工作
解决方案
你可以添加
$gifts = json_decode($gifts)
到您的 PHP 代码。见这里。
或者,正如 xyz 建议的那样,在 javascript 端解析它,比如
JSON.parse(data)
毕竟,这与引号无关,但它最终必须被您的 Javascript 代码理解为 JSON。
推荐阅读
- ios - 按日期分组过滤结果而不将所有内容转储到内存
- sql - SQL 查询,它搜索具有特定数组列项的所有行
- python-3.x - 如何设置通用工作目录?
- ios - 如何设置 Jenkins 来构建使用 Carthage 的 React Native iOS 应用程序?
- graphql - AWS AppSync GraphQL - 使用联合作为突变返回导致错误
- java - 没有从属性文件中获取整数值
- ruby-on-rails - 带有语义 UI 滑轨的图像循环
- reactjs - 执行某些特定 HTTP 动词后如何执行某些代码
- ruby - 如何在 ubuntu 19.04 上安装 rvm install 2.1.1
- python - eos_vlan 和 ansible,“cli 命令“vlan 777”失败:无效命令”