Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I want to display the questions and options in Json which is from database. I want output like this,

[
{
"survey_question_id": 1,
"survey_question_text": "How long does it take to get a new print supplier approved and set up to work with your company?",
"survey_question_option_order": 1,
"survey_question_type": "radio",
"survey_question_comment_req": true,
"survey_question_active": true,
"survey_question_option_active": true ,
“options”:[
{
"survey_question_option_value": "There is no formal supplier approval process.",
"survey_question_option_text": "There is no formal supplier approval process."
},
{
"survey_question_option_value": "There is no formal supplier approval process.",
"survey_question_option_text": "There is no formal supplier approval process."
},
{
"survey_question_option_value": "There is no formal supplier approval process.",
"survey_question_option_text": "There is no formal supplier approval process."
}
]

But when i tried i got like this output,

[
{
"survey_question_id": 1,
"survey_question_text": "How long does it take to get a new print supplier approved and set up to work with your company?",
"survey_question_option_value": "There is no formal supplier approval process.",
"survey_question_option_text": "There is no formal supplier approval process.",
"survey_question_option_order": 1,
"survey_question_type": "radio",
"survey_question_comment_req": true,
"survey_question_active": true,
"survey_question_option_active": true
},
{
"survey_question_id": 1,
"survey_question_text": "How long does it take to get a new print supplier approved and set up to work with your company?",
"survey_question_option_value": "We do have an approval process, but the approval happens right away",
"survey_question_option_text": "We do have an approval process, but the approval happens right away",
"survey_question_option_order": 2,
"survey_question_type": "radio",
"survey_question_comment_req": true,
"survey_question_active": true,
"survey_question_option_active": true
},
{
"survey_question_id": 1,
"survey_question_text": "How long does it take to get a new print supplier approved and set up to work with your company?",
"survey_question_option_value": "A few days",
"survey_question_option_text": "A few days",
"survey_question_option_order": 3,
"survey_question_type": "radio",
"survey_question_comment_req": true,
"survey_question_active": true,
"survey_question_option_active": true
},
{
"survey_question_id": 1,
"survey_question_text": "How long does it take to get a new print supplier approved and set up to work with your company?",
"survey_question_option_value": "A few weeks",
"survey_question_option_text": "A few weeks",
"survey_question_option_order": 4,
"survey_question_type": "radio",
"survey_question_comment_req": true,
"survey_question_active": true,
"survey_question_option_active": true
},
{
"survey_question_id": 1,
"survey_question_text": "How long does it take to get a new print supplier approved and set up to work with your company?",
"survey_question_option_value": "A month or more",
"survey_question_option_text": "A month or more",
"survey_question_option_order": 5,
"survey_question_type": "radio",
"survey_question_comment_req": true,
"survey_question_active": true,
"survey_question_option_active": true
},

I am new for JSON. Anybody can help me?

What I have tried:

I am new for json and i changed in coding and script. But it is not working. Anybody can help? Please help me.
Posted
Updated 28-Sep-16 23:04pm
Comments
Suvendu Shekhar Giri 29-Sep-16 3:42am    
It's just the JSON data, where is the coding which you have done but not working?
Also share the error details.
Member 10556393 29-Sep-16 3:46am    
Hi, thanks for your reply. I just fetch data from database using sp. The sp looks like create procedure usp_GetQuestionWithOptionList
as
begin

select
sq.survey_question_id,
sq.survey_question_text,
sqo.survey_question_option_value,
sqo.survey_question_option_text,
sqo.survey_question_option_order,
sq.survey_question_type,
sq.survey_question_comment_req,
sq.survey_question_active,
sqo.survey_question_option_active
from
survey_questions sq inner join survey_question_options sqo on sq.survey_question_id = sqo.survey_question_id
order by sq.survey_question_id,sqo.survey_question_option_order
End

1 solution

See Introduction[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900