Android 앱을 사용하고 있으며 사용자가 키워드를 입력하고 앱을 보여줄 수있는 기본 검색 기능으로 API를 통해 앱에 Khan 연결을 시도하고 있습니다. 검색 기준과 일치하는 주제/동영상/연습 목록이지만 API가 공식 "키워드로 검색"방법을 제공하지 않으므로 거의 불가능하다는 것을 알았습니다. Khan과 함께 일하는 모든 사람은 전체를 다운로드 할 수 없음을 알고 있습니다. 주제 나무는 70MB 파일로 끝납니다.Khan Academy에서 키워드로 검색
많은 어려움을 겪고 고생하면서 고생하고 있지만 문제를 해결하는 방법에 대한 문서를 찾을 수 없었으므로 도움을 청합니다. 누구든지이 문제를 처리하는 방법에 대한 아이디어가 있거나 성공적으로 수행 한 사람이 어떤 방향으로 어떤 힌트를 줄 수 있습니까?
나는 (예를 들어) http://www.khanacademy.org/api/v1/topictree?kind=topic을 할 수 있지만이 필터로도 json 결과는 거대합니다 (10mb 이상의 데이터 스트림).
private static String connect2Url(String urlString){
URL url;
HttpURLConnection urlConnection = null;
InputStream inStream = null;
StringBuilder response = new StringBuilder();
try {
url = new URL(urlString);
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoInput(true);
urlConnection.connect();
inStream = urlConnection.getInputStream();
BufferedReader bReader = new BufferedReader(new InputStreamReader(inStream));
String temp = "";
while ((temp = bReader.readLine()) != null) {
response.append(temp);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (inStream != null) {
try {
inStream.close();
} catch (IOException ignored) {
}
}
if (urlConnection != null) {
urlConnection.disconnect();
}
}
return response.toString();
}
그리고 나는이 결과로 된 JSONObject를 만듭니다
이
내가 JSON을 스트리밍하는 방법입니다.현재로서는 "http://www.khanacademy.org/api/v1/topic/%s"을 (를) URL로 전달하지만이 경우 ID (주제 슬러그)로만 주제를 찾을 수 있지만 무료 검색을 할 수는 없습니다.
좋아, 누구든지 도울 수 있기를 바랍니다. 감사드립니다.
편집 :
AlphaQ 제안 사항에 따라 이미 GSON 잭슨에 대해 물론 조사하고있어 그와 함께 동의 내 구문 분석 기능은 큰 JSON 스트리밍을위한 효율적인 아니지만 어쨌든 나는 두 가지 문제로 실행 해요의 첫 번째는 json 구조가 Khan Academy에서 반환 한 클래스의 클래스를 만드는 것은 상당히 복잡합니다 (생각합니다). 두 번째는 더 효율적인 구문 분석을 수행 할 수있는 경우에도 서버에서 Khan Academy json 응답을 필터링 할 수있는 경우입니다. 14MB의 데이터를 가져옵니다 (전체 트리가 70MB). 어쨌든 14MB를 다운로드해야하고 Khan Academy API가 제공하지 않기 때문에 내 기능이 얼마나 최적화되어 있는지에 관계없이 모바일 앱에 너무 많은 것 같습니다. "키워드로 검색"방법.
14MB가 너무 많은 json 데이터로 모바일 앱을 스트리밍한다고 생각하지 않습니까?
{
"icon_src": "",
"twitter_url": "",
"domain_slug": null,
"relative_url": "/",
"creation_date": "2016-12-14T00:46:38Z",
"web_url": "",
"ka_url": "https://www.khanacademy.org/",
"translated_standalone_title": "Khan Academy",
"has_user_authored_content_types": true,
"translated_title": "Khan Academy",
"gplus_url": "",
"children": [{
"icon_src": "",
"twitter_url": "",
"domain_slug": "new-and-noteworthy",
"relative_url": "/new-and-noteworthy",
"creation_date": "2016-09-13T20:35:19Z",
"web_url": "",
"ka_url": "https://www.khanacademy.org/new-and-noteworthy",
"translated_standalone_title": "New and noteworthy",
"has_user_authored_content_types": false,
"translated_title": "New and noteworthy",
"gplus_url": "",
"children": [],
"hide": false,
"node_slug": "new-and-noteworthy",
"title": "New and noteworthy",
"child_data": [{
"kind": "Video",
"id": "1101921746"
}, {
"kind": "Video",
"id": "796509722"
}, {
"kind": "Video",
"id": "796388970"
}, {
"kind": "Video",
"id": "753767269"
}, {
"kind": "Video",
"id": "225139731"
}, {
"kind": "Video",
"id": "225139729"
}, {
"kind": "Video",
"id": "988721865"
}, {
"kind": "Video",
"id": "884313452"
}, {
"kind": "Video",
"id": "671536496"
}, {
"kind": "Video",
"id": "887553535"
}, {
"kind": "Video",
"id": "1049279550"
}, {
"kind": "Video",
"id": "796535894"
}, {
"kind": "Video",
"id": "796307891"
}, {
"kind": "Video",
"id": "1094139389"
}, {
"kind": "Video",
"id": "796502981"
}, {
"kind": "Video",
"id": "796434657"
}, {
"kind": "Video",
"id": "871510490"
}, {
"kind": "Video",
"id": "884392300"
}, {
"kind": "Video",
"id": "x77e83a17"
}, {
"kind": "Video",
"id": "884395195"
}, {
"kind": "Video",
"id": "1077533640"
}, {
"kind": "Video",
"id": "1094227108"
}, {
"kind": "Video",
"id": "1094119956"
}, {
"kind": "Video",
"id": "1112847811"
}, {
"kind": "Video",
"id": "1114711148"
}, {
"kind": "Video",
"id": "1081957510"
}, {
"kind": "Video",
"id": "1095856196"
}, {
"kind": "Video",
"id": "1090948774"
}, {
"kind": "Video",
"id": "1013985489"
}, {
"kind": "Video",
"id": "xca214ba1"
}
],
"user_authored_content_types_info": [],
"id": "x29232c6b",
"user_authored_content_types": [],
"translated_description": "",
"alternate_slugs": [],
"standalone_title": "New and noteworthy",
"logo_image_url": "",
"in_knowledge_map": false,
"description": "",
"tags": [],
"deleted": false,
"listed_locales": [],
"facebook_url": "",
"render_type": "UncuratedTutorial",
"background_image_url": "",
"background_image_caption": "",
"has_peer_reviewed_projects": false,
"topic_page_url": "/new-and-noteworthy",
"extended_slug": "new-and-noteworthy",
"deleted_mod_time": "2013-07-13T00:03:09Z",
"kind": "Topic",
"curation": {},
"slug": "new-and-noteworthy",
"do_not_publish": false,
"sha": "a6c251bd225b9d23e1a98f1a7fce3ccd0c8cb4fa",
"branding_image_url": "",
"current_revision_key": "a6c251bd225b9d23e1a98f1a7fce3ccd0c8cb4fa",
"content_id": "x29232c6b",
"content_kind": "Topic",
"curriculum_key": ""
}, {
"icon_src": "",
"twitter_url": "",
"domain_slug": "math",
"relative_url": "/math",
"creation_date": "2017-05-08T20:15:34Z",
"web_url": "",
"ka_url": "https://www.khanacademy.org/math",
"translated_standalone_title": "Math",
"has_user_authored_content_types": false,
"translated_title": "Math",
"gplus_url": "",
"children": [{
"icon_src": "",
"twitter_url": "",
"domain_slug": "math",
"relative_url": "/math/k-8-grades",
"creation_date": "2017-03-17T23:26:26Z",
"web_url": "",
"ka_url": "https://www.khanacademy.org/math/k-8-grades",
"translated_standalone_title": "K-8th grades",
"has_user_authored_content_types": false,
"translated_title": "K-8th grades",
"gplus_url": "",
"children": [],
"hide": false,
"node_slug": "k-8-grades",
"title": "K-8th grades",
"child_data": [],
"user_authored_content_types_info": [],
"id": "xf3cb93f0",
"user_authored_content_types": [],
"translated_description": "",
"alternate_slugs": [],
"standalone_title": "K-8th grades",
"logo_image_url": "",
"in_knowledge_map": false,
"description": "",
"tags": [],
"deleted": false,
"listed_locales": ["fr", "en", "pt", "de", "tr", "pl", "nb", "es"],
"facebook_url": "",
"render_type": "Subject",
"background_image_url": "",
"background_image_caption": "",
"has_peer_reviewed_projects": false,
"topic_page_url": "/math/k-8-grades",
"extended_slug": "math/k-8-grades",
"deleted_mod_time": null,
"kind": "Topic",
"curation": {
"modules": [{
"content": ["Video:xd2b0fcb4", "Article:x175a9d66", "Video:x102d9798", "Exercise:2015", "Exercise:3022"],
"referrer": "k_8_grades_staff_picks",
"kind": "ContentCarousel",
"title": "Staff picks"
}, {
"topic": "Topic:xd0ae8a03",
"kind": "SubjectIntro"
}
],
"whitelist": ["Topic:xfe881476a971a3cb", "Topic:xb5feb28c", "Topic:xcef32ab6", "Topic:xef8f4cb4", "Topic:x3184e0ec", "Topic:xc7f617f2", "Topic:x5ec3eb59", "Topic:xb830458a", "Topic:x0267d782", "Topic:x6b17ba59", "Topic:x7c7044d7", "Topic:xa617314f", "Topic:x8708676b", "Topic:x7ed4701d", "Topic:x6ee1f3c2", "Topic:x0f2eb71b", "Topic:xa18e5391"],
"hide_community_questions": true
},
편집 : 2 :
내가 AlphaQ 저를 제안 모든 GSON 문서를 읽고 몇 가지 예제를 체크 아웃 한
하지만 내 JSON 응답이 예제로 JSON 응답에서 약간의 추출물 조금 복잡하기 때문에 매핑 클래스를 정의하는 방법을 이해할 수 없습니다.
다음은 json을 받고있는 URL입니다.
정확하게 매핑 클래스를 정의하는 방법에 대한 도움을 주시면 감사하겠습니다.
http://www.khanacademy.org/api/v1/topictree
(이 어떤 필터링없이하지만 추가 할 수 있습니다?kind = 주제는 전체 주제 목록을 볼 수 있지만 필터는 더 이상 허용되지 않습니다.)
위의 내용은 GSMON에서도 가능할 것이라고 생각하지 않지만, 가능하면 좋을 것입니다. 이 거대한 파일에서 모든 수학 주제를 검색하기 위해이
http://www.khanacademy.org/api/v1/topic/math
을한다.
json이 너무 크고 복잡하기 때문에이를위한 매핑 클래스를 만드는 방법을 알 수는 없습니다. 나는 "어린이"노드 아래에있는 주제의 URL, 제목 및 설명 만 필요합니다.
효율적 파싱을 위해 JSON 파싱 라이브러리, 즉 'GSON' 또는'Jackson'을 사용해보십시오. – AlphaQ
Hello AlphaQ와 같은 빠른 응답을 주셔서 감사합니다. 귀하의 회신에 대한 자세한 의견은 제 편집을 참조하십시오. –
json을 deserialize하기 위해 클래스를 생성하는 경우 json에서 추출 할 속성 만 거기에 넣으십시오. Gson은 해당 속성 만 채 웁니다. – nbokmans