Conversion between json and object using SBJson lib
2013-08-20 21:19
417 查看
Define two methods in an object class as follows:
Convert json to object
Convert object to json string
@interface MyObject : NSObject @property (nonatomic,copy) NSString *property; - (id)initWithJson:(NSDictionary *)item; - (id)proxyForJson; - (id)initWithJson:(NSDictionary *)item { self = [superinit]; if (self) { self.property = [itemobjectForKey:@"Property"]; } return self; } - (id) proxyForJson { return [NSDictionarydictionaryWithObjectsAndKeys:property,@"Property", nil]; }
Convert json to object
NSData *dataReply = [NSURLConnectionsendSynchronousRequest:urlRequest returningResponse:&response error:&error]; NSDictionary *results = [dataReply JSONValue]; MyObject *object = [[MyObjectalloc] initWithJson:results];
Convert object to json string
MyObject *object = [[MyObjectalloc]init];
NSString*json = [objectJSONRepresentation];
相关文章推荐
- Conversion between json and object using SBJson lib
- Conversion between json and object using SBJson lib
- conversion between xml and object using xstream
- Conversion between json and object
- Conversion between json and object
- Conversion between json and object
- Convert an object into Json using SBJson or other JSON library
- what is the difference between json and javascript object.
- Conversion between JSON and JAVA (struts Ajax)
- csharp:Conversion Between DataTable and List
- Json-lib使用——JSONObject与JSONArray
- json-lib使用,JSONObject和JSONArray .
- conversion between Mat and BufferedImage
- Android JSON And Object Cast
- 百度天气api开发 全解析xml和json格式 使用json-lib jsonObject、 Gson 方式把json 转换成 java对象
- 关于json-lib中JSONObject的formString静态方法
- Example: Communication between Activity and Service using Messaging
- using JavaScriptSerializer to serialize object to json
- Json-lib使用——JSONObject与JSONArray
- Modifying a JSON object by creating a New Field using existing Elements