람다의 내 코드는AWS (λ)는 Node.js를에서 자바
dynamodb.query(params
, function(err, data) {
if (err) {
context.done(err);
}
else {
console.log(JSON.stringify(data)); // successful response
var size = data.Items.length;
console.log("size:"+ size);
var rand = Math.floor(Math.random() * (size));
console.log("rand" + rand);
var ret = data.Items[rand].content;
console.log(ret);
context.succeed(JSON.stringify(ret));
}
내 AWS 람다 로그 ("을 console.log (JSON.stringify (데이터));// 성공적인 응답 JSON.stringify (RET) ")
{"Items":[{"content":{"S":"content1"}},{"content":{"S":"content2"}}],"Count":2,"ScannedCount":2}
그리고의 결과이다", "내 안드로이드 코드에서
{"S":"content1"}
,이 API를 호출하고 바로 입술 보여 ult. 하지만 "java.lang.String을 JSONObject로 변환 할 수 없습니다."
Android에서 JSONObject로 변환하는 방법을 궁금합니다.
나는 문제는 당신이getJSONObject
을 요구하고있다 안드로이드
new JSONObject(notice).getJSONObject("S");
번 확인하여'디버깅 변수 notice'. "변환 할 수 없습니다"오류는 일반적으로 구문 문제가있을 때 발생합니다. – donkon
안녕하세요 @ 동콘 통지 변수가 "{"S ":"content1 "}"입니다. 그것은 틀리지 않습니다. 그래서 그것은 나를 미치게 만든다. 내가 무슨 소리를 더 많이 확인하니? – larsien
답변을 게시했습니다 – donkon