参考地址:http://msgpack.org
Install
pod "MPMessagePack"
Writing
#import <MPMessagePack/MPMessagePack.h>

NSDictionary *dict =
@{
@"n": @(32134123),
@"bool": @(YES),
@"array": @[@(1.1f), @(2.1)],
@"body": [NSData data],
};

NSData *data = [dict mp_messagePack];

Or via MPMessagePackWriter.

NSError *error = nil;
NSData *data = [MPMessagePackWriter writeObject:dict error:&error];

If you need to use an ordered dictionary.

MPOrderedDictionary *dict = [[MPOrderedDictionary alloc] init];
[dict addEntriesFromDictionary:@{@"c": @(1), @"b": @(2), @"a": @(3)}];
[dict sortKeysUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
[dict mp_messagePack];
Reading
id obj = [MPMessagePackReader readData:data error:&error];
MPMessagePackReader *reader = [[MPMessagePackReader alloc] initWithData:data];
id obj1 = [reader read:&error]; // Read an object
id obj2 = [reader read:&error]; // Read another object

相关文章:

  • 2022-12-23
  • 2021-08-18
  • 2021-05-30
  • 2021-05-01
  • 2022-12-23
  • 2022-01-25
  • 2022-01-06
猜你喜欢
  • 2018-01-21
  • 2018-02-14
  • 2021-07-29
  • 2021-12-14
  • 2021-05-03
  • 2021-05-23
  • 2022-12-23
相关资源
相似解决方案