0
我想用一個唯一的數字替換json中的內容,比如說uuid。 我的json是替換爲uuid(或隨機數)
let response =
{
"data": {
"address": [
{
"city": "wildcard"
},
{
"city": "wildcard"
}
]
}
}
我想用唯一的數字替換通配符。
我的代碼是
response = response.replace(new RegExp('wildcard','g'), uuid.v4());
其替換與單個UUID的JSON所有的通配符,我希望每個通配符具有獨特uuid.v4更換()。
基本上我需要幫助每次調用uuid.v4()時更換通配符?
當您嘗試調用'replace'時,您在此處的代碼會導致錯誤。請分享您測試過的實際代碼。 – smarx
如果'response'實際上是一個字符串,請嘗試'response = response.replace(new RegExp('wildcard','g'),uuid.v4);' – smarx
爲什麼不寫你的Math.random()而不是uuid。 V4()? –