开发者

HTTP Plain-text data to array

开发者 https://www.devze.com 2023-02-16 21:12 出处:网络
I\'m using the iOS device to access data on a local module, and it gets info from http://.../path_to/file.bin, and the response is in plain-text as:

I'm using the iOS device to access data on a local module, and it gets info from http://.../path_to/file.bin, and the response is in plain-text as:

[Header]
Version=1
[Data]
SomeData=aValue
StringKey=Value
TimestampKey=DDD:HH:MM:SS
NumberKey=8321
[Blob]
MoreData=moreValues
[EOF]
Lines=11

(timestamp only occurs once and is a time from the current time)

I would like to put all of the information in the string above into a NSDictionary to be more easily accessible. Something appearing like:

Dictionary (
    Header => Dictionary (
        Version => 1
开发者_运维问答    )
    Data => Dictionary (
        SomeData => aValue,
        StringKey => anotherValue,
        TimestampKey => "DDD:HH:MM:SS", //(format into NSDate if you like)
        NumberKey => 8321 //(format into int if you like)
    }
    Blob => Dictionary (
        MoreData => moreValues
    )
)

So I would enjoy a function that would format the string input into the dictionary output.


two solutions:

  • reformat your data (plist or json) to load them with existing frameworks
  • write your own parser

Here's an example on CocoaWithLove

0

精彩评论

暂无评论...
验证码 换一张
取 消