从 Blackberry 中的服务解析 JSON 格式的字符串/数组
我正在尝试向服务器发送一些数据,因此一旦收到数据或在处理事务时发生任何错误,服务器将通过 JSON 类型的响应向其客户端告知。当我发布一个设置值时,正如我所说,它返回一个如下所示的 JSON 格式,
{"code":0,"err":"Missing 'method'."}. // JSON format returned from the server
/** Method that is responsible for converting the JSON format to other types*/
public static void convertFromJSON(String json) throws JSONException {
// the string json holds JSON format string that i mentioned above
// Creates a JSONArray with the values provided in the string json
JSONArray entries = new JSONArray(json); // error : The constructor JSONArray(String) refers to the missing type JSONException
}
我需要解析这个 JSON 格式并根据它返回的值对其进行评估。我也导入了适当的 JSON JAR。
任何帮助表示赞赏
谢谢。
I am trying to send some data to a server, so once the data is received or any error occurs while the transaction is processing, the server would intimate to its clients through a JSON type of response. when i post a a set value , as i said, its it returns a JSON format like the one below,
{"code":0,"err":"Missing 'method'."}. // JSON format returned from the server
/** Method that is responsible for converting the JSON format to other types*/
public static void convertFromJSON(String json) throws JSONException {
// the string json holds JSON format string that i mentioned above
// Creates a JSONArray with the values provided in the string json
JSONArray entries = new JSONArray(json); // error : The constructor JSONArray(String) refers to the missing type JSONException
}
I need to parse this JSON format and evaluate it depending upon the value that it returns. I have imported the appropriate JSON JAR too.
Any help is appreciated
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试以下操作。
Try the following.
我建议http://code.google.com/p/json-simple/:
此外,您提供的示例不会解析为 JSONArray。
I'd recommend http://code.google.com/p/json-simple/:
Also, the sample you've provided won't parse into a JSONArray.