当我想要以下方式时,我如何在PHP中编码以获取序列号 [英] How do i code in php to get the serial number when i want the following way
问题描述
当我想要以下json格式的方式时,我如何编码获取序列号?
{
Rec:[{
SlNo:1
名称:,
DOB:
}]
}
我尝试过:
if(getenv('REQUEST_METHOD')=='POST')
{
echo{\Rec\: [;
how do i code to get the serial number when i want the following way of json format?
{
"Rec": [{
"SlNo":1
"Name": " ",
"DOB": " "
}]
}
What I have tried:
if(getenv('REQUEST_METHOD') == 'POST')
{
echo "{\"Rec\":[";
推荐答案
JSON使用JavaScript语法,了解更多信息 JSON Tutorial [ ^ ]
这个
JSON uses JavaScript syntax, learn more JSON Tutorial[^]
this
{"Rec": [{"SlNo":1,"Name": " ","DOB": " "}]}
表示一个名为Rec的json数组,它包含一个具有这些属性 - 值对的对象元素{SlNo:1,Name:,DOB:} 。
获取这些属性值的两种方法之一是通过对象方式。学习 PHP:类和对象 - 手册 [ ^ ]
represents a json array called "Rec" that contains one object element with these property-value pairs {"SlNo":1,"Name": " ","DOB": " "}.
One of the two ways to get the values of these property is through the object way. Learn PHP: Classes and Objects - Manual[^]
<?php
json = ' {Rec:[{SlNo:1,Name:,DOB:}}}'';
// 将其解码为对象
json = '{"Rec": [{"SlNo":1,"Name": " ","DOB": " "}]}'; // decode it to an object
object = json_decode(
object = json_decode(
这篇关于当我想要以下方式时,我如何在PHP中编码以获取序列号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!