그래서 나를위한 몇 가지 질문에 대한 정보를 담고있는 JSON 개체를 만들려고합니다. 이것은 내가 그것을 제시하는 방법의 의사 코드 :올바른 JSON 형식 가져 오기
{
"page" : 1,
"info" :
{
"id" : 1,
"type" : 3,
"description": "How to do JSON?",
"alternatives" :
{
"id" : 1,
"description" : "Dunno"
}
{
"id" : 2,
"description" : "Let me show you"
}
{
"id" : 3,
"description" : "I refuse to show you"
}
}
"id" : 2,
"type" : 1,
"description": "Do you get it?",
"alternatives" :
{
"id" : 1,
"description" : "Yes"
}
{
"id" : 2,
"description" : "No"
}
}
}
그래서 코드는 아래 에서 악몽 (답변 중 하나)이며, 나는 페이지와 수행 할 작업을 정확하게 수행 그리고 질문들,하지만 나는 각 질문에 대안들을 연결하는 방법을 알아낼 수 없다. 내가 시도한 부분에서 스 니펫을 볼 수는 있지만 철자가 정확하지 않고 잠시 동안이 부분을 망치고 있습니다.
$before_json_encode[$row['page']][] = array(
'id' => $row['id'],
'type' => $row['type'],
'description' => $row['description'],
'alternatives' => $alternativesarray//im not sure about here,dont know the structure of the alternative array
);
JSON 데이터의 계층 구조를 어떻게 표시할지에 대한 또 다른 그림. 예를 들어 선택할 수 있어야합니다. 특정 페이지의 모든 질문에 대한 모든 대안. 따라서 설문 조사에서 페이지 3을 생성하려면 먼저 3 페이지 하위 배열에서 질문을 찾은 다음 각 질문에서 다시 모든 질문에 액세스 할 수 있습니다. 그 질문 자체의 하위 배열에 연결된 대안이 있습니다. 내 문제의 빈약 한 설명 죄송합니다, 그냥 조금 복잡 :/
Page
Question
Alternative
Alternative
Alternative
Question
Alternative
Alternative
Alternative
Question
Alternative
Alternative
Page
Question
Alternative
Alternative
Question
Alternative
Alternative
업데이트 : 3 층 :
$rows_test2[$r['page']]
['id' => $r['id'],
'type' => $r['type'],
'description' => $r['description']]
[] =
array (
'altid' => $t['altid'],
'altdesc' => $t['altdesc']);
당신은'$ alternativesarray []'이'$의 alternativesarray' 또는'$의 alternativesarray [#의 ID 번호] 안' –
"정말 작동하지 않습니다이"정말 아무것도 의미하지 않는다. 얼마나 정확하게 작동하지 않습니까? – lanzz
데이터베이스에서 결과를 가져온 다음 json_encode를 사용하여 배열을 Json 형식으로 변환합니다. http://php.net/manual/en/function.json-encode.php – Vimalnath