我有一个像这样的JSON。因此,如何获取基本的URL类型:https://obs.line-scdn.net/0hLbl4V2I5E01RTTg_zdxsGmMfFC0_IQhTc3lCeS0dDiEgNQxHPX0IK3wfH3R9ehEaPS9ceH0eSg/L100x100 \?
Image :[ {
"id": 1,
"thumbnail": "[{\"url\":\"https://obs.line-scdn.net/0hLbl4V2I5E01RTTg_zdxsGmMfFC0_IQhTc3lCeS0dDiEgNQxHPX0IK3wfH3R9ehEaPS9ceH0eSg/L100x100\",\"width\":100},{\"url\":\"https://obs.line-scdn.net/0hLbl4V2I5E01RTTg_zdxsGmMfFC0_IQhTc3lCeS0dDiEgNQxHPX0IK3wfH3R9ehEaPS9ceH0eSg/L200x200\",\"width\":200},{\"url\":\"https://obs.line-scdn.net/0hLbl4V2I5E01RTTg_zdxsGmMfFC0_IQhTc3lCeS0dDiEgNQxHPX0IK3wfH3R9ehEaPS9ceH0eSg/L500x500\",\"width\":500},{\"url\":\"https://obs.line-scdn.net/0hLbl4V2I5E01RTTg_zdxsGmMfFC0_IQhTc3lCeS0dDiEgNQxHPX0IK3wfH3R9ehEaPS9ceH0eSg/L1000x1000\",\"width\":1000}]",
"category": {
"id": 2,
"title": "title"
},
"title": "look good",
"rank": 6,
"is_new": false,
"is_pr": false
}]
var{ data } = this.props;
const image = data ? data.thumbnail : "";
const convert = image ? image.replace("[","").replace("]", "") : "";
let img = "";
if (convert.length !== 0) {
img = convert ? JSON.parse(convert).url :"";
}
console.log(convert)
const imageStyle = {
backgroundImage: `url(${img})`,
};`
答案 0 :(得分:-1)
您需要部署Web API,它将返回此json对象。部署后,您将获得URL。所以你可以在react组件中使用 fetch(urlForApi).then(res => res.json())。then(data => HereIsTheData)