Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Blackberry 从json格式字符串转换为json对象的问题_Blackberry_Json - Fatal编程技术网

Blackberry 从json格式字符串转换为json对象的问题

Blackberry 从json格式字符串转换为json对象的问题,blackberry,json,Blackberry,Json,我有一个web servlet,它返回一个json,它以json格式的字符串形式存储在我的bb移动应用程序中 现在我想解析字符串以从中提取值。。。 使用 返回一个错误: json必须以{ 我生成的JSON就是这种格式 [ {"LASTNAME":"akre","FIRSTNAME":"swapnil"}, {"LASTNAME":"akre","FIRSTNAME":"swapnil"}, {"LASTNAME":"akre","FIRSTNAME":"swapnil"} ]

我有一个web servlet,它返回一个json,它以json格式的字符串形式存储在我的bb移动应用程序中

现在我想解析字符串以从中提取值。。。 使用

返回一个错误:

json必须以{

我生成的JSON就是这种格式

[
   {"LASTNAME":"akre","FIRSTNAME":"swapnil"},
   {"LASTNAME":"akre","FIRSTNAME":"swapnil"},
   {"LASTNAME":"akre","FIRSTNAME":"swapnil"}
]
这是经jsonlint.com验证的corect格式…

我假设您正在使用


您的JSON是一个数组,因此您必须使用
JSONArray
类来解析它

是的,JSON必须以
{
开始,以
}
结束,您可以做的是将JSON数组放入
{}
,因此它将被正确解析。JsonLint也会解析部分json,这就是它显示为正确的原因。您可以尝试以下方法


是的,json必须以
{
开头,以
}
结尾,您可以做的是将json数组放入
{}
中,这样就可以像jsonobject.JsonLint解析部分json一样正确地解析它,这就是为什么它显示为正确的原因

{
    "data": [
        {
            "LASTNAME": "akre",
            "FIRSTNAME": "swapnil"
        },
        {
            "LASTNAME": "akre",
            "FIRSTNAME": "swapnil"
        },
        {
            "LASTNAME": "akre",
            "FIRSTNAME": "swapnil"
        }
    ]
}

所以这些数据也有同样的问题。。。
{
    "data": [
        {
            "LASTNAME": "akre",
            "FIRSTNAME": "swapnil"
        },
        {
            "LASTNAME": "akre",
            "FIRSTNAME": "swapnil"
        },
        {
            "LASTNAME": "akre",
            "FIRSTNAME": "swapnil"
        }
    ]
}