【问题标题】:Reading a Javascript file in a Bundle to String Xcode IOS将 Bundle 中的 Javascript 文件读取为字符串 Xcode IOS
【发布时间】:2012-01-20 17:42:36
【问题描述】:

我已经尝试过多种方式,但它从未将我的文件作为字符串弹出。任何帮助将非常感激。或许一双新的眼睛就能明白。

static NSString *JSParse;


JSParse = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"nameFinder" ofType:@"js" ] encoding:NSUTF8StringEncoding ];
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"nameFinder" ofType:@"js"];
NSLog(filepath);
if (filepath)
{
    NSString *someJscript = [NSString stringWithContentsOfFile:filepath];
    NSLog(someJscript);
}
NSLog(@"StartParse");
NSLog(JSParse);
NSLog(@"End Parse");

最终目标是使用 javascript 从不属于我的网站解析 HTML,是的,这很糟糕。 (虽然我的代码在这一点上也很可疑,但正在解析);

【问题讨论】:

    标签: ios xcode string bundle


    【解决方案1】:

    解决办法在这里:https://stackoverflow.com/a/2018644/526547

    如果你使用这种方法,你不需要将你的 .js 更改为 .txt。

    【讨论】:

    【解决方案2】:

    原因与它是一个 JS 文件扩展名有关。将其更改为 txt 文件总是可以解决问题。我不确定为什么会这样,但我假设这是一些编译问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 2014-05-13
      • 1970-01-01
      • 2015-12-03
      • 1970-01-01
      • 2016-12-15
      相关资源
      最近更新 更多