0

当我使用 NSURLconnection 发送请求时返回的数据包含这样的脚本

<script>
var baseURL = "main.aspx?";
var lang = 1;
lg(0,8375,"AFC U-22 Championship Qualifirs","http://images.goalzz.com/i.aspx?i=competitions%2fafc_small_icon.gif");
mc(0,752017,1,"","11:45®<br><nobr>&nbsp;<font color=yellow>playing",1298,"","Malaysia","","",2163,"","Myanmar","","<font color=#427384>Week: 5<br>","",0);
mc(0,752021,2,"","12:00®<br><nobr>&nbsp;<font color=yellow>playing",7849,"","Laos","","",2158,"","Cambodia","","<font color=#427384>Week: 5<br>","",0);
mc(0,752022,3,"","12:00®<br><nobr>&nbsp;<font color=yellow>playing",479,"","Bahrain","","",1574,"","Iran","","<font color=#427384>Week: 5<br>","",0);
lg(6,8048,"Wimbledon - Men","http://images.goalzz.com/i.aspx?i=tennis%2ftennis_small.gif");
mc(6,754074,4,"","10:30®<br><nobr><font color=yellow>2nd Set",274,"","Brian Baker  - <font size=-1 color=black>United States</font>","","<font color=blue>1&nbsp;:&nbsp;1</font>",110,"","<font size=-1 color=orange>(27) </font>Philipp Kohlschreiber  - <font size=-1 color=black>Germany</font>","","<font color=red>Round 4<br>","",0);
mc(6,754076,5,"","10:30®<br><nobr><font color=yellow>2nd Set",342,"","<font size=-1 color=orange>(5) </font>Jo-Wilfried Tsonga  - <font size=-1 color=black>France</font>","","<font color=blue>0&nbsp;:&nbsp;1</font>",282,"","<font size=-1 color=orange>(10) </font>Mardy Fish  - <font size=-1 color=black>United States</font>","","<font color=red>Round 4<br>","",0);
mc(6,753844,6,"","10:30®<br><nobr><font color=yellow>3rd Set",5,"","<font size=-1 color=orange>(18) </font>Richard Gasquet  - <font size=-1 color=black>France</font>","","<font color=blue>1&nbsp;:&nbsp;2</font>",86,"","<font size=-1 color=orange>(31) </font>Florian Mayer  - <font size=-1 color=black>Germany</font>","","<font color=red>Round 4<br>","",0);
mc(6,754075,7,"","11:00®<br><nobr><font color=yellow>2nd Set",107,"","<font size=-1 color=orange>(7) </font>David Ferrer  - <font size=-1 color=black>Spain</font>","","<font color=blue>1&nbsp;:&nbsp;1</font>",669,"","<font size=-1 color=orange>(9) </font>Juan Martin Del Potro  - <font size=-1 color=black>Argentina</font>","","<font color=red>Round 4<br>","",0);
mc(6,754092,8,"","11:00®<br><nobr><font color=yellow>3rd Set",675,"","<font size=-1 color=orange>(16) </font>Marin Cilic  - <font size=-1 color=black>Croatia</font>","","<font color=blue>0&nbsp;:&nbsp;2</font>",16,"","<font size=-1 color=orange>(4) </font>Andy Murray  - <font size=-1 color=black>United Kingdom</font>","","<font color=red>Round 4<br>","",0);
</script>

我想在 lg 节点中提取 (AFC U-22 Championship Qualifirs) 文本,在 mc 节点中提取 (Malaysia,Myanmar) 文本。这可能吗?

4

2 回答 2

0

您将不得不进行一些字符串操作和搜索

例如,您可以搜索 Champion (Championship Qualifirs",") 和第一次出现的 ") 之间的字符串;

对于马来西亚和缅甸使用类似的搜索方法,没有可以解析这种字符串的内置函数

如果您可以控制此请求,请考虑使用 JSON 或 XML 作为远程数据

于 2012-07-03T12:51:46.747 回答
0

您需要在此进行字符串搜索。此链接将帮助您实现此目的。您可以按照以下步骤操作。

  1. 在您从连接收到的文本数据中搜索“lg(”。
  2. 然后搜索逗号“,”的第二次出现并从下一个位置提取所有字符,直到它没有得到双引号“””。
  3. 然后移动您的索引并在文本中搜索“mc(”。
  4. 现在搜索逗号“,”的第 7 次出现并从下一个位置提取所有字符,直到它没有得到双引号“””。

现在你可以得到两个字符串。

祝你好运

于 2012-07-03T13:15:04.480 回答