1

我从服务器调用收到 JSON 字符串,格式如下:

{"0":{"jpgN":"2","spread_value":"392.22","relevant_new":"text"},"1":{"jpgN":"1","spread_value":"395.28","relevant_new":"text"},"count":2}

使用 RegExp,有没有办法用字符串"http://mydomain.com/keyValue.jpg"(例如"http://mydomain.com/2.jpg")替换任何键 jpgN 的值?

4

2 回答 2

2

替换"jpgN":"([^"]+)""jpgN":"http://mydomain.com/$1.jpg"

但最好使用您的编程语言解析 json 并更改值。

于 2012-04-20T08:14:52.007 回答
1

类似的东西?

var json = {"0":{"jpgN":"2","spread_value":"392.22","relevant_new":"text"},"1":{"jpgN":"1","spread_value":"395.28","relevant_new":"text"},"count":2};
var s = JSON.stringify(json);

s.replace(/\"jpgN\":\"(\w+)\"/g, "\"jpgN\":\"http://mydomain.com/$1.jpg\"");
于 2012-04-20T08:12:38.247 回答