jQuery - 从字符串中获取特定短语

时间:2013-07-01 12:04:46

标签: jquery

我拥有的字符串示例:

{"prices":"","sTld":"com","sSld":"test1","available":false,"type":"","options":""}
{"prices":"","sTld":"co.uk","sSld":"test2","available":false,"type":"","options":""}
{"prices":"","sTld":"in","sSld":"test3","available":false,"type":"","options":""}
{"prices":"","sTld":"lt","sSld":"test4","available":false,"type":"","options":""}

我想提取这些值:

com, co.uk, in, lt
test1, test2, test3, test4

换句话说,我想从sTld中提取从“:”到“的每个值,以及从”:“到”的sSld中的值。

我想我需要使用正则表达式,但我不知道如何。有什么建议?

2 个答案:

答案 0 :(得分:1)

试试这个,

var obj=[{"prices":"","sTld":"com","sSld":"test1","available":false,"type":"","options":""},
{"prices":"","sTld":"co.uk","sSld":"test2","available":false,"type":"","options":""},
{"prices":"","sTld":"in","sSld":"test3","available":false,"type":"","options":""},
{"prices":"","sTld":"lt","sSld":"test4","available":false,"type":"","options":""}];
$.each(obj, function(index, value) {
    console.log(value.sTld);
    console.log(value.sSld);
});

Fiddle

答案 1 :(得分:0)

$.each(json, function(index, value) {
    console.log(value.sTld);
    console.log(value.sSld);
});