Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Json中获取Json,并使用jquery将其放入文本框中_Jquery_Html_Ajax - Fatal编程技术网

在Json中获取Json,并使用jquery将其放入文本框中

在Json中获取Json,并使用jquery将其放入文本框中,jquery,html,ajax,Jquery,Html,Ajax,我有这样的输出 [{…}] 0: id: 3 url_generation: "https://mail.google.com/mail/u/0/#sent" status: "status one" certificate: "[{"med_sbj_list":"Certificate1"},{"med_sbj_list":"Certificate2"},{"med_sbj_list":"Certificate3"},{"med_sbj_list":null},{"med_sbj_list":

我有这样的输出

[{…}]
0:
id: 3
url_generation: "https://mail.google.com/mail/u/0/#sent"
status: "status one"
certificate: "[{"med_sbj_list":"Certificate1"},{"med_sbj_list":"Certificate2"},{"med_sbj_list":"Certificate3"},{"med_sbj_list":null},{"med_sbj_list":null},{"med_sbj_list":null}]"
name: "Doctor 1"
alphabet_name: "Doctor one"
image: "/doctor_photos/GSmdfr_Screenshot_20200114_102036.jpg"
image_caption: "this is an image caption"
image_alt: "image alt"
industry: "industry two"
conference: "[{"conf":"Conference1"},{"med_sbj_list":"Conference2"},{"conf":"Conference3"},{"conf":null},{"conf":null},{"conf":null}]"
birthday: "03-6-2018"
place_of_birth: "cebu city"
career_academic_back: "[{"from_year":"1991","from_month":"02","from_desc":"aaa","to_year":"1995","to_month":"06","to_desc":"bbb"}]"
career_work_exp: "[{"we_from_year":"1997","we_from_month":"05","we_from_desc":"ccc","we_to_year":"1997","we_to_month":"06","we_to_desc":"ddd"}]"
career_awards: "[{"from_year":"1998","from_month":"08","from_desc":"eee","to_year":"1999","to_month":"09","to_desc":"fff"}]"
sort_career: "1"
hospital_office: "industry one"
department: "[{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"}]"
doctor_comment: "this is a sample comment of the doctor."
created_at: "2020-01-22 03:50:28"
updated_at: "2020-01-22 03:50:28"
__proto__: Object
length: 1
__proto__: Array(0)
我想获取json类型的
证书
会议
值,并将其分别放在文本框中。见下图

这是我的jquery代码

$.ajax({
                url: '/modal_edit_doctor/'+id,
                type: 'get',
                dataType: 'json',
                success: function(response){
                    console.log(response['data']);
                if(response == "success")
                  console.log(response['data']); 
                  $("#editdoctor").modal('show');
                  $("#url_generation").val(response['data'][0].url_generation);
                  $("#status").val(response['data'][0].status);
                  var objJSON = JSON.parse(response['data'][0].certificate);
                  console.log(objJSON);


                    $("#name").val(response['data'][0].name);
                    $("#alpha_name").val(response['data'][0].alphabet_name);
                    //image not included yet
                    $("#img_caption").val(response['data'][0].image_caption);
                    $("#img_alt").val(response['data'][0].image_alt);
                    //industry dropdown not included yet
                    //conference json not included yet
                    //birthday not included yet
                    $("#place_birth").val(response['data'][0].place_of_birth);
                    //the 3 careers not included yet
                    //checkbox not included yet
                    //hospital dropdown not included yet
                    //department json not included yet
                    $("#doc_comment").val(response['data'][0].doctor_comment);


                },
                    error: function(response){
                    alert('Error'+response);

                }

              });

循环通过它
objJSON
,您将访问数据。我想你想要这个

#textboxes is your text field id, maybe value or text you want to display.
$.each(objJSON, function(key,value){
   $("#textboxes").text(value.med_sbj_list);
});

这将是这样的,我不擅长jquery,但我会编写EJS

用这个来了解你的想法

var certificate1=document.getElementbyId('certificate1')

certificate1.innerHTML=


您必须首先获取certificate行,因为您可以看到证书行是一个数组,所以请像数组一样使用它来访问它。

然后向我们显示您的jQuery代码。是否要将值字符串转换为json?然后解析它
JSON.parse(certificate)
并循环遍历它们以显示$.each(object.certificate,function(index,value){console.log(value.med_sbj_list);});将打印下的所有med_sbj_列表certificate@RiteshKhandekar我已经更新了上面的代码。但是您面临的实际问题是什么?她使用的是jquery而不是EJS亲爱的,您的答案应该与实际问题相关。