开发者

Java Objective-C Json data

I have a little problem with understanding this too lines of code in Objective-C :

id jsonData;
NSInteger errorCode;
NSString* errorString;
errorCode = [jsonData sqlInt:@"error_code"];
errorString = [[jsonData objectForKey:@"error_string"] retain];

I'm trying to find a way how to do the same code in Java,that's why I need a little help to understand this piece of code. Thanks in advance!!!

EDIT: Is this code do the same as in Objective C? :

 ErrorCode = new JSONObject();
    ErrorCode.put("error_code", errorCode);
    ErrorString = new JSONObject();
    ErrorString.put("error_string", e开发者_StackOverflowrrorString);


Try this ,

SBJSON *jsonData = [SBJSON alloc]init]; - Objective c

private JSONObject jObject; - Java

// you get a JSON Data - Objective C

NSDictionary *errorString = [[jsonData objectForKey:@"error_string"] retain];

For Java -

jObject = new JSONObject(errorString); 

JSONArray menuitemArray = popupObject.getJSONArray("error_string");

String attributeValue = jObject.getString("value");

System.out.println(attributeValue);


Presumably your jsonData is in a dictionary of some sort, and presumably sqlInt is either a "category" extension to NSDictionary or a method of some custom dictionary class that is being used by the JSON parser. From its name it takes a named element of some sort and returns its int representation.

So you have two elements in your dictionary, one named "error_code" and one named "error_string". "error_string" can simply be extracted into a String, but "error_code" is either an Integer object or a String representation of an integer -- can't tell which from your code (but you can tell by looking at the source JSON -- An Integer value will NOT be surrounded by quotes, but a String value will).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜