JSONを解析しようとしていますが、問題が発生しています。
これが私がすでに試したことです:
ContentValues categories = new ContentValues();
JSONObject json = new JSONObject(improvedInputStreamAsString);
Iterator keys = json.keys();
while(keys.hasNext()) {
Object newObj = keys.next();
String jsonString = newObj.toString();
if(jsonString == "children") {
JSONObject newJsn = new JSONObject(jsonString);
if(newJsn.has("name")) {
String category = newJsn.getString("name");
categories.put("categories", category);
}
}
}
からカテゴリを取得しようとしているだけですJSONObject
が、何らかの理由でjsonString
に評価されませんchildren
。
構造は次のとおりです。申し訳ありませんが、JSONの大部分を貼り付けたため、JSONが非常に混乱し、整合性を維持しながら切り詰めるのが困難でした。name
フィールドを取得しようとしているだけであることを忘れないでください。
{
"position": "0",
"children": [
{
"position": "1",
"children": [
{
"position": "1",
"children": [
{
"position": "3",
"children": [
],
"category_id": "9",
"level": "3",
"is_active": "1",
"name": "Exfoliants",
"parent_id": "4"
},
{
"position": "4",
"children": [
],
"category_id": "10",
"level": "3",
"is_active": "1",
"name": "Moisturisers",
"parent_id": "4"
},
{
"position": "5",
"children": [
],
"category_id": "11",
"level": "3",
"is_active": "1",
"name": "Treatments",
"parent_id": "4"
},
{
"position": "6",
"children": [
],
"category_id": "12",
"level": "3",
"is_active": "1",
"name": "Cleansers",
"parent_id": "4"
},
{
"position": "7",
"children": [
],
"category_id": "13",
"level": "3",
"is_active": "1",
"name": "Skin Toners",
"parent_id": "4"
},
{
"position": "9",
"children": [
],
"category_id": "15",
"level": "3",
"is_active": "1",
"name": "Serums",
"parent_id": "4"
},
{
"position": "10",
"children": [
],
"category_id": "36",
"level": "3",
"is_active": "1",
"name": "Acne and Blemish Treatments",
"parent_id": "4"
},
{
"position": "11",
"children": [
],
"category_id": "40",
"level": "3",
"is_active": "1",
"name": "Oils",
"parent_id": "4"
}
],
"category_id": "4",
"level": "2",
"is_active": "1",
"name": "Skincare",
"parent_id": "2"
},
{
"position": "2",
"children": [
{
"position": "1",
"children": [
],
"category_id": "16",
"level": "3",
"is_active": "1",
"name": "Sunscreen",
"parent_id": "5"
},
{
"position": "2",
"children": [
],
"category_id": "31",
"level": "3",
"is_active": "1",
"name": "Insect Repellent & After Bite",
"parent_id": "5"
},
{
"position": "3",
"children": [
],
"category_id": "32",
"level": "3",
"is_active": "1",
"name": "After Sun Lotions",
"parent_id": "5"
},
{
"position": "4",
"children": [
],
"category_id": "33",
"level": "3",
"is_active": "1",
"name": "Self Tanning Lotions",
"parent_id": "5"
}
],
"category_id": "5",
"level": "2",
"is_active": "1",
"name": "Suncare",
"parent_id": "2"
},
{
"position": "3",
"children": [
{
"position": "1",
"children": [
],
"category_id": "17",
"level": "3",
"is_active": "1",
"name": "Shampoo",
"parent_id": "6"
},
{
"position": "2",
"children": [
],
"category_id": "18",
"level": "3",
"is_active": "1",
"name": "Conditioner",
"parent_id": "6"
},
{
"position": "3",
"children": [
],
"category_id": "19",
"level": "3",
"is_active": "1",
"name": "Treatments",
"parent_id": "6"
},
{
"position": "4",
"children": [
],
"category_id": "20",
"level": "3",
"is_active": "1",
"name": "Toner",
"parent_id": "6"
},
{
"position": "6",
"children": [
],
"category_id": "34",
"level": "3",
"is_active": "1",
"name": "Styling",
"parent_id": "6"
},
{
"position": "7",
"children": [
],
"category_id": "39",
"level": "3",
"is_active": "1",
"name": "Serum",
"parent_id": "6"
}
],
"category_id": "6",
"level": "2",
"is_active": "1",
"name": "Hair",
"parent_id": "2"
},
{
"position": "0",
"children": [
{
"position": "1",
"children": [
{
"position": "1",
"children": [
{
"position": "3",
"children": [
],
"category_id": "9",
"level": "3",
"is_active": "1",
"name": "Exfoliants",
"parent_id": "4"
},
{
"position": "6",
"children": [
],
"category_id": "12",
"level": "3",
"is_active": "1",
"name": "Cleansers",
"parent_id": "4"
},
],
"category_id": "4",
"level": "2",
"is_active": "1",
"name": "Skincare",
"parent_id": "2"
},
{
"position": "2",
"children": [
{
"position": "1",
"children": [
],
"category_id": "16",
"level": "3",
"is_active": "1",
"name": "Sunscreen",
"parent_id": "5"
},