댓글의 JSON 출력
본문
댓글이 아래와 같은 구조로 되어 있을 때, 이 댓글에 대한 JSON 출력을 어떤식으로 주면
프런트엔드에서 편하게 사용이 가능할까요?
아래와 같이 JSON을 받으면 쉽게 화면에 디스플레이가 가능할까요?
아니면 더 좋은 방법이 있는지요?
{
"comments": [
{
"wrId": 1,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 0,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "",
"wrContent": "댓글 1",
"comments": [
{
"wrId": 2,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 1,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "A",
"wrContent": "댓글 1-1",
"comments": [
{
"wrId": 3,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 2,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AA",
"wrContent": "댓글 1-1-1",
"comments": [
{
"wrId": 4,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 3,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AAA",
"wrContent": "댓글 1-1-1-1",
"comments": [
{
"wrId": 6,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 4,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AAAA",
"wrContent": "댓글 1-1-1-1-1",
"comments": [
{
"wrId": 8,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 6,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AAAAA",
"wrContent": "댓글 1-1-1-1-1-1",
"comments": []
},
{
"wrId": 16,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 6,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AAAAB",
"wrContent": "댓글 1-1-1-1-1-2",
"comments": []
}
]
}
]
}
]
},
{
"wrId": 5,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 2,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AB",
"wrContent": "댓글 1-1-2",
"comments": []
}
]
},
{
"wrId": 7,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 1,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "B",
"wrContent": "댓글 1-2",
"comments": [
{
"wrId": 13,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 7,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "BA",
"wrContent": "댓글 1-2-1",
"comments": []
}
]
}
]
},
{
"wrId": 9,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 0,
"wrIsComment": 1,
"wrComment": 2,
"wrCommentReply": "",
"wrContent": "댓글 2",
"comments": [
{
"wrId": 10,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 9,
"wrIsComment": 1,
"wrComment": 2,
"wrCommentReply": "A",
"wrContent": "댓글 2-1",
"comments": [
{
"wrId": 15,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 10,
"wrIsComment": 1,
"wrComment": 2,
"wrCommentReply": "AA",
"wrContent": "댓글 2-1-1",
"comments": []
}
]
}
]
},
{
"wrId": 11,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 0,
"wrIsComment": 1,
"wrComment": 3,
"wrCommentReply": "",
"wrContent": "댓글 3",
"comments": [
{
"wrId": 12,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 11,
"wrIsComment": 1,
"wrComment": 3,
"wrCommentReply": "A",
"wrContent": "댓글 3-1",
"comments": [
{
"wrId": 14,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 12,
"wrIsComment": 1,
"wrComment": 3,
"wrCommentReply": "AA",
"wrContent": "댓글 3-1-1",
"comments": []
}
]
},
{
"wrId": 17,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 11,
"wrIsComment": 1,
"wrComment": 3,
"wrCommentReply": "B",
"wrContent": "댓글 3-2",
"comments": []
}
]
}
]
}
답변 3
저라면 지금구조 좋은데요?
저라면..
그냥
wrCommentParent 와
wrCommentReply로 구분이 되니
1.댓글
대댓글11
대대댓글111
구조로 리스트만 나열해서
wrCommentReply 의 length로
들여쓰기 깊이로만 로만 처리를 하는게 낫지 않을까 생각합니다.
{
"comments": [
{
"wrId": 1,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 0,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "",
"wrContent": "댓글 1",
},
{
"wrId": 2,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 0,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "A",
"wrContent": "댓글 1",
},
{
"wrId": 2,
"wrReply": "",
"wrParent": 1,
"boTable": "free",
"wrCommentParent": 0,
"wrIsComment": 1,
"wrComment": 1,
"wrCommentReply": "AA",
"wrContent": "대댓글 1",
},
}
형태로..말이죠
!-->
"wrComment": 1, // 이것이 comments의 length 역할을 하니까
recursive-loop 돌릴 때 유용하지 않을까요?
"wrCommentReply": "",
"wrContent": "댓글 1",
"comments": []
답변을 작성하시기 전에 로그인 해주세요.