简体   繁体   English

Java Objective-C Json数据

[英]Java Objective-C Json data

I have a little problem with understanding this too lines of code in Objective-C : 在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. 我正在尝试找到一种如何在Java中使用相同代码的方法,这就是为什么我需要一些帮助来理解这段代码。 Thanks in advance!!! 提前致谢!!!

EDIT: Is this code do the same as in Objective C? 编辑:此代码与Objective C中的代码相同吗? :

 ErrorCode = new JSONObject();
    ErrorCode.put("error_code", errorCode);
    ErrorString = new JSONObject();
    ErrorString.put("error_string", errorString);

Try this , 尝试这个 ,

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

private JSONObject jObject; - Java

// you get a JSON Data - Objective C //你得到一个JSON数据 - 目标C.

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

For Java - 对于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. 据推测,你的jsonData在某种字典中,并且可能是sqlInt是NSDictionary的“类别”扩展或者是JSON解析器正在使用的一些自定义字典类的方法。 From its name it takes a named element of some sort and returns its int representation. 从它的名称,它采用某种类型的命名元素并返回其int表示。

So you have two elements in your dictionary, one named "error_code" and one named "error_string". 因此,字典中有两个元素,一个名为“error_code”,另一个名为“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). “error_string”可以简单地提取到一个String中,但“error_code”可以是一个Integer对象,也可以是一个整数的String表示形式 - 无法分辨出你的代码(但你可以通过查看源JSON来判断 - Integer值不会被引号括起来,但是String值会被包围。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM