gpt4 book ai didi

string - 如何在同一行中多次拆分字符串?

转载 作者:行者123 更新时间:2023-12-01 22:21:17 25 4
gpt4 key购买 nike

我正在尝试通过将其拆分为字符串来操纵收到的响应正文,有没有办法我可以在一行中获取ProductName而不是将其拆分为两行?
/script>dataLayer.push({'ecommerce':{'detail':{'products':[{'name':'adidas Stan Smith cwhite / cwhite / dkblue','id':'017795','price' :'1983','brand':'adidas','category':'Sneakers','sale':'No sale','saleType':'Sale:0%','variant':``}]} }}); dataLayer.push({'ecomm_prodid':['017795'],'ecomm_pagetype':'product','ecomm_totalvalue':2399.00});(function(w,d,s,l,i){w [l] = w [l] || []; w [l] .push({'gtm.start':new Date()。getTime(),event:'gtm.js'}); var f = d .getElementsByTagName(s)
编辑:这是从我拆分的html的块,我正在尝试使用一行代码来获取“adidas Stan Smith cwhite / cwhite / dkblue”


import (
"io/ioutil"
"log"
"net/http"
"strings"
)

func main() {
for {
log.Println("Sending..")
resp, _ := http.Get("https://www.queens.global/59789/adidas-stan-smith/")

defer resp.Body.Close()

body, _ := ioutil.ReadAll(resp.Body)

product := strings.Split(string(body), "name': '")[1]
productName := strings.Split(product, "', 'id':")[0]
log.Println(productName)
break
}
}

最佳答案

{"ecommerce": { "detail": { "products": [{ "name": "adidas Stan Smith cwhite / cwhite / dkblue", "id": "017795", "price": "1983", "brand": "adidas", "category": "Sneakers", "sale": "No sale", "saleType": "Sale: 0 %", "variant": ""}]}}}
输出(字符串)中的此部分是JSON。
获取所有内容的最佳方法是将相同内容解析为JSON,然后从相同变量中获取结果。
您可以使用新的GSON()。toJSON()相同(或任何JSON解析器)

关于string - 如何在同一行中多次拆分字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63331083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com