ios LINESTRING 解析

标签 ios xcode json parsing dictionary

我一直在 iOS 版谷歌地图中以自定义方式规划路线。

如何解析 LINESTRING 中传入的 JSON?

我的线路:

"coordInfo": "LINESTRING (28.646751729297 40.9993029074749, 28.6470087874434 40.9995465119554, 28.6470087874434 40.9995465119554, 28.6474633603416 41.0000088561426)"
    },

最佳答案

从您发布的内容来看,objectForKey@"coordInfo"为您提供了一个带有括号内数字的字符串。您可以使用 NSString 方法 elementsSeparatedByCharactersInSet 进行解析:传递一个包含左括号、右括号、逗号和空格的集合,以生成单个数字字符串的数组(以及单词“LINESTRING”作为数组中的第一个字符串) 。该数组还将包含一些空字符串,其中 2 个分隔符字符在一起(例如逗号和空格),因此在从数组中取出对象时必须对此进行测试。

您还可以像这样使用 NSScanner:

NSString *toParse = @"LINESTRING (28.646751729297 40.9993029074749, 28.6470087874434 40.9995465119554, 28.6470087874434 40.9995465119554, 28.6474633603416 41.0000088561426)";
    NSScanner *scanner = [NSScanner scannerWithString:toParse];
    double num;
    while (! [scanner isAtEnd]) {
      [scanner scanUpToCharactersFromSet:[NSCharacterSet decimalDigitCharacterSet] intoString:nil];
      [scanner scanDouble:&num];
      // put numbers into an array here or use them somehow
      NSLog(@"%f",num);
    }

关于ios LINESTRING 解析,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11937362/

相关文章:

ios - 好用的Afnetworking/Nsurlsession/Alamofire

ios - 使用 Firebase 在 iOS 13.2 中登录导航/Segue

ios - 在 swift 4 中访问相机和照片库

iphone - SQLite "SQLITE MISUSE"错误

swift - 如何将 String 转换为 UnsafeMutablePointer<UInt8> ? swift 3

javascript - 一旦在数组中找到匹配项,如何停止JavaScript循环

javascript - 无法使用请求读取python Rest中的axios数据

ios - 适用于 iCloud 的大量 UIDocuments

ios - 通过-weak_library 弱链接静态库

java - 使用 Jackson 将 json 字符串转换为 List<List<String>