aptitude_PHP JSON Aptitude问题与解答

aptitude

This section contains Aptitude Questions and Answers on PHP JSON.

本节包含有关PHP JSON的 Aptitude问题和解答。

1) There are the following statements that are given below, which of them are correct about JSON in PHP?
  1. JSON stands for JavaScript Object Notation.

  2. JSON stands for JavaScript OOPS Notation.

  3. JSON is a data format that is used to store and exchange data.

  4. JSON is a text-based format.

Options:

  1. A and C

  2. B and C

  3. A, C, and D

  4. D

Answer & Explanation

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.

1)下面给出了以下语句,其中哪些对于PHP中的JSON是正确的?
  1. JSON代表JavaScript对象符号。

  2. JSON表示JavaScript OOPS表示法。

  3. JSON是一种用于存储和交换数据的数据格式。

  4. JSON是基于文本的格式。

选项:

  1. A和C

  2. B和C

  3. A,C和D

  4. d

答案与解释

正确答案:3
A,C和D

说明:

JSON是一种基于文本的格式,用于存储服务器之间的数据并与之交换数据。JSON格式被多种编程语言使用。

2) Which of the following function is used to encode the data into JSON format?
  1. jsonencode()

  2. json_encode()

  3. encode_json()

  4. None of the above

Answer & Explanation

Correct answer: 2
json_encode()

Explanation:

The json_encode() is a built-in function which is used encode data into JSON format.

2)以下哪个函数用于将数据编码为JSON格式?
  1. jsonencode()

  2. json_encode()

  3. encode_json()

  4. 以上都不是

答案与解释

正确答案:2
json_encode()

说明:

json_encode()是一个内置函数,用于将数据编码为JSON格式。

3) What is the correct output of given code snippets in PHP?
<?php
$roll_no = array(
    "SHAURYA" => 101,
    "DUGGU" => 102,
    "Joe" => 103
);
echo json_encode($roll_no);
?>

  1. {"SHAURYA":101,"DUGGU":102,"Joe":103}

  2. {"SHAURYA"->101,"DUGGU"->102,"Joe"->103}

  3. {"SHAURYA"=>101,"DUGGU"=>102,"Joe"=>103}

  4. None of the above

Answer & Explanation

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.

3)PHP中给定代码段的正确输出是什么?
  1. {“ SHAURYA”:101,“ DUGGU”:102,“ Joe”:103}

  2. {“ SHAURYA”-> 101,“ DUGGU”-> 102,“ Joe”-> 103}

  3. {“ SHAURYA” => 101,“ DUGGU” => 102,“ Joe” => 103}

  4. 以上都不是

答案与解释

正确答案:1
{“ SHAURYA”:101,“ DUGGU”:102,“ Joe”:103}

说明:

在上面的代码中, json_encode()函数以JSON格式编码或转换数组值。

4) What is the correct output of given code snippets in PHP?
<?php
$students = array(
    "SHAURYA",
    "DUGGU",
    "Joe"
);
echo json_encode($students);
?>

  1. {"SHAURYA","DUGGU","Joe"}

  2. ["SHAURYA","DUGGU","Joe"]

  3. <"SHAURYA","DUGGU","Joe">

  4. ("SHAURYA","DUGGU","Joe")

Answer & Explanation

Correct answer: 2
["SHAURYA","DUGGU","Joe"]

Explanation:

The above code will print ["SHAURYA","DUGGU","Joe"] on the web page.

4)PHP中给定代码段的正确输出是什么?
  1. {“ SHAURYA”,“ DUGGU”,“ Joe”}

  2. [“ SHAURYA”,“ DUGGU”,“ Joe”]

  3. <“ SHAURYA”,“ DUGGU”,“乔”>

  4. (“ SHAURYA”,“ DUGGU”,“ Joe”)

答案与解释

正确答案:2
[“ SHAURYA”,“ DUGGU”,“ Joe”]

说明:

上面的代码将在网页上打印[“ SHAURYA”,“ DUGGU”,“ Joe”]。

5) What is the correct output of given code snippets in PHP?
<?php
$students = '["SHAURYA","DUGGU","Joe"]';
echo json_decode($students);
?>

  1. {"SHAURYA","DUGGU","Joe"}

  2. Error

  3. Array

  4. None of the above

Answer & Explanation

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.

5)PHP中给定代码段的正确输出是什么?
  1. {“ SHAURYA”,“ DUGGU”,“ Joe”}

  2. 错误

  3. 数组

  4. 以上都不是

答案与解释

正确答案:3
数组

说明:

json_decode()函数在解码JSON格式后返回一个数组。 但是我们不能直接打印数组,我们需要使用循环来访问数组元素,或者我们可以使用索引来访问单个元素。

6) What is the correct output of given code snippets in PHP?
<?php
$students = '["SHAURYA","DUGGU","Joe"]';
echo var_dump(json_decode($students));
?>

  1. {"SHAURYA","DUGGU","Joe"}

  2. ["SHAURYA","DUGGU","Joe"]

  3. array(3) { [0]=> string(7) "SHAURYA" [1]=> string(5) "DUGGU" [2]=> string(3) "Joe" }

  4. None of the above

Answer & Explanation

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.

6)PHP中给定代码段的正确输出是什么?
  1. {“ SHAURYA”,“ DUGGU”,“ Joe”}

  2. [“ SHAURYA”,“ DUGGU”,“ Joe”]

  3. array(3){[0] =>字符串(7)“ SHAURYA” [1] =>字符串(5)“ DUGGU” [2] =>字符串(3)“ Joe”}

  4. 以上都不是

答案与解释

正确答案:3
array(3){[0] =>字符串(7)“ SHAURYA” [1] =>字符串(5)“ DUGGU” [2] =>字符串(3)“ Joe”}

说明:

json_decode()函数在解码JSON格式的数据后返回数组,然后我们使用var_dump()打印数组,然后将以下数据打印在网页上。

7) What is the correct output of given code snippets in PHP?
<?php
	$students = {"SHAURYA":101,"DUGGU":102,"Joe":103};
	echo var_dump(json_decode($students));
?>

  1. object(stdClass)#1 (3) { ["SHAURYA"]=> int(101) ["DUGGU"]=> int(102) ["Joe"]=> int(103) }

  2. {"SHAURYA","DUGGU","Joe"}

  3. Garbage value

  4. Error

Answer & Explanation

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:

7)PHP中给定代码段的正确输出是什么?
 <?php
	$students = { "SHAURYA" : 101 , "DUGGU" : 102 , "Joe" : 103 };
	echo var_dump ( json_decode ( $students ));
?>

  1. object(stdClass)#1(3){[“” SHAURYA“] => int(101)[” DUGGU“] => int(102)[” Joe“] => int(103)}

  2. {“ SHAURYA”,“ DUGGU”,“ Joe”}

  3. 垃圾价值

  4. 错误

答案与解释

正确答案:4
错误

说明:

上面的代码将产生错误,因为在这里我们没有在$ student变量中正确分配值,在这里我们需要将数据括在单引号中,如下所示:

8) What is the correct output of given code snippets in PHP?
<?php
$students = '{"SHAURYA":101,"DUGGU":102,"Joe":103}';

$data = json_decode($students);
echo $data->DUGGU;
?>

  1. 102

  2. DUGGU

  3. Error

  4. None of the above

Answer & Explanation

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.

8)PHP中给定代码段的正确输出是什么?
  1. 102

  2. 杜古

  3. 错误

  4. 以上都不是

答案与解释

正确答案:1
102

说明:

上面的代码将在网页上打印102,这里json_decode()函数解码JSON数据并返回一个对象,然后我们可以访问JSON项目并进行打印。

9) What is the correct output of given code snippets in PHP?
<?php
$students = '{"SHAURYA":101,"DUGGU":102,"Joe":103}';

$data = json_decode($students);
echo $data['DUGGU'];
?>

  1. 102

  2. DUGGU

  3. Error

  4. None of the above

Answer & Explanation

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.

9)PHP中给定代码段的正确输出是什么?
  1. 102

  2. 杜古

  3. 错误

  4. 以上都不是

答案与解释

正确答案:3
错误

说明:

上面的代码将产生一个错误,因为在上面的代码中json_decode()返回一个对象,但是我们想要打印类似关联数组的数据,那么我们需要在json_decode()函数中再传递一个参数,然后它将返回一个关联数组,那么我们需要在代码中使用json_decode($ students,true)函数调用。

10) Can we transfer JSON data using the web-method call in the web service implementation?
  1. Yes

  2. No

Answer & Explanation

Correct answer: 1
Yes

Explanation:

Yes, we can transfer JSON data using the web-method call in the web service implementation.

10)我们可以在Web服务实现中使用Web方法调用来传输JSON数据吗?
  1. 没有

答案与解释

正确答案:1

说明:

是的,我们可以使用Web服务实现中的Web方法调用来传输JSON数据。

翻译自: https://www.includehelp.com/php/json-aptitude-questions-and-answers.aspx

aptitude

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值