我有以下JSON字符串
{
"PlayListName":"PlayList1","CountOfFilesinPlayList":5,
"PlayListArray":[
{"DevId":1,"FileId":1,"Title":"This is a test %% @_1_1","m_iFileType":0},{"DevId":1,"FileId":2,"Title":"This is a test %% @_1_2","m_iFileType":1},{"DevId":2,"FileId":3,"Title":"This is a test %% @_2_3","m_iFileType":0},{"DevId":2,"FileId":4,"Title":"This is a test %% @_2_4","m_iFileType":2},{"DevId":3,"FileId":5,"Title":"This is a test %% @_3_5","FileType":0}]
}
虽然使用 libJSON,但我能够获取: 的值
"PlayListName"
, "CountOfFilesinPlayList"
并且还可以识别"PlayListArray"
,但我无法找出如何提取"PlayListArray"
.
以下是解析JSON字符串的代码片段
int_n nCountOfFiles;
PlayList_st *pPlaylistArr;
int8_n szPlayListName[PLAYLIST_NAME_LENGTH];
json_object *new_obj;
enum json_type type;
new_obj = json_tokener_parse\
((char *)args[0].value.stringValue.UTF8Characters);
if(!new_obj) {
result->type = NPVariantType_Bool;
result->value.boolValue = false;
return false;
}
json_object_object_foreach(new_obj, key, val) {
type = json_object_get_type(val);
switch(type) {
case json_type_int:
if(key && !strcmp((const char *)key, "CountOfFilesinPlayList"))
{
nCountOfFiles = json_object_get_int(val);
/* Allocate pPlaylistName array */
if(nCountOfFiles > 0)
{
.....
.....
}
else
{
.....
.....
}
}
break;
case json_type_string:
if(key && !strcmp((const char *)key, "PlayListName"))
{
strncpy (szPlayListName, json_object_get_string(val), \
PLAYLIST_NAME_LENGTH-1);
}
break;
case json_type_array:
if(key && !strcmp((const char *)key, "PlayListArray"))
{
MEDIA_DEBUG_PRINT("\nwcf Media plugin: Found PlayListArray");
}
break;
default:
result->type = NPVariantType_Bool;
result->value.boolValue = false;
return false;
}
}