aptitude
This section contains Aptitude Questions and Answers on PHP JSON.
本节包含有关PHP JSON的 Aptitude问题和解答。
JSON stands for JavaScript Object Notation.
JSON stands for JavaScript OOPS Notation.
JSON is a data format that is used to store and exchange data.
JSON is a text-based format.
Options:
Correct answer: 3
A, C, and D
Explanation:
JSON is a text-based format, which is used to store and exchange data from or to a server, JSON format is used by multiple programming languages.
JSON代表JavaScript对象符号。
JSON表示JavaScript OOPS表示法。
JSON是一种用于存储和交换数据的数据格式。
JSON是基于文本的格式。
选项:
正确答案:3
A,C和D
说明:
JSON是一种基于文本的格式,用于存储服务器之间的数据并与之交换数据。JSON格式被多种编程语言使用。
Correct answer: 2
json_encode()
Explanation:
The json_encode() is a built-in function which is used encode data into JSON format.
正确答案:2
json_encode()
说明:
json_encode()是一个内置函数,用于将数据编码为JSON格式。
<?php
$roll_no = array(
"SHAURYA" => 101,
"DUGGU" => 102,
"Joe" => 103
);
echo json_encode($roll_no);
?>
Correct answer: 1
{"SHAURYA":101,"DUGGU":102,"Joe":103}
Explanation:
In the above code json_encode() function encode or convert array value in the JSON format.
正确答案:1
{“ SHAURYA”:101,“ DUGGU”:102,“ Joe”:103}
说明:
在上面的代码中, json_encode()函数以JSON格式编码或转换数组值。
<?php
$students = array(
"SHAURYA",
"DUGGU",
"Joe"
);
echo json_encode($students);
?>
Correct answer: 2
["SHAURYA","DUGGU","Joe"]
Explanation:
The above code will print ["SHAURYA","DUGGU","Joe"] on the web page.
正确答案:2
[“ SHAURYA”,“ DUGGU”,“ Joe”]
说明:
上面的代码将在网页上打印[“ SHAURYA”,“ DUGGU”,“ Joe”]。
<?php
$students = '["SHAURYA","DUGGU","Joe"]';
echo json_decode($students);
?>
Correct answer: 3
Array
Explanation:
The json_decode() function returns an array after decoding JSON format. But we cannot print array directly, we need to use a loop to access array elements or we can access individual elements using the index.
正确答案:3
数组
说明:
json_decode()函数在解码JSON格式后返回一个数组。 但是我们不能直接打印数组,我们需要使用循环来访问数组元素,或者我们可以使用索引来访问单个元素。
<?php
$students = '["SHAURYA","DUGGU","Joe"]';
echo var_dump(json_decode($students));
?>
Correct answer: 3
array(3) { [0]=> string(7) "SHAURYA" [1]=> string(5) "DUGGU" [2]=> string(3) "Joe" }
Explanation:
The json_decode() function returns array after decoding JSON formatted data, and then we print array using var_dump() then following data will be printed on web page.
正确答案:3
array(3){[0] =>字符串(7)“ SHAURYA” [1] =>字符串(5)“ DUGGU” [2] =>字符串(3)“ Joe”}
说明:
json_decode()函数在解码JSON格式的数据后返回数组,然后我们使用var_dump()打印数组,然后将以下数据打印在网页上。
<?php
$students = {"SHAURYA":101,"DUGGU":102,"Joe":103};
echo var_dump(json_decode($students));
?>
Correct answer: 4
Error
Explanation:
The above code will generate an error because here we did not assign value in $student variable properly, here we need to enclose data into single quotes like this:
<?php
$students = { "SHAURYA" : 101 , "DUGGU" : 102 , "Joe" : 103 };
echo var_dump ( json_decode ( $students ));
?>
正确答案:4
错误
说明:
上面的代码将产生错误,因为在这里我们没有在$ student变量中正确分配值,在这里我们需要将数据括在单引号中,如下所示:
<?php
$students = '{"SHAURYA":101,"DUGGU":102,"Joe":103}';
$data = json_decode($students);
echo $data->DUGGU;
?>
Correct answer: 1
102
Explanation:
The above code will print 102 on web page, here json_decode() function decodes JSON data and return an object then we can access JSON items and print them.
正确答案:1
102
说明:
上面的代码将在网页上打印102,这里json_decode()函数解码JSON数据并返回一个对象,然后我们可以访问JSON项目并进行打印。
<?php
$students = '{"SHAURYA":101,"DUGGU":102,"Joe":103}';
$data = json_decode($students);
echo $data['DUGGU'];
?>
Correct answer: 3
Error
Explanation:
The above code will generate an error , because in the above code json_decode() return an object, but we want to print data like associative array, then we need to pass one more argument in json_decode() function then it will return an associative array, then we need to use json_decode($students,true) function call in our code.
正确答案:3
错误
说明:
上面的代码将产生一个错误,因为在上面的代码中json_decode()返回一个对象,但是我们想要打印类似关联数组的数据,那么我们需要在json_decode()函数中再传递一个参数,然后它将返回一个关联数组,那么我们需要在代码中使用json_decode($ students,true)函数调用。
Correct answer: 1
Yes
Explanation:
Yes, we can transfer JSON data using the web-method call in the web service implementation.
翻译自: https://www.includehelp.com/php/json-aptitude-questions-and-answers.aspx
aptitude