第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

php轉(zhuǎn)換成json數(shù)據(jù)格式 ?

php轉(zhuǎn)換成json數(shù)據(jù)格式 ?

動(dòng)漫人物 2019-01-31 20:03:41
{ "programmers": [ { "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" }, { "firstName": "Jason", "lastName":"Hunter", "email": "bbbb" }, { "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }],"authors": [ { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" }, { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" }, { "firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction" } ], "musicians": [ { "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" }, { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" } ] } 這樣的數(shù)據(jù)格式是怎么樣轉(zhuǎn)換的我從數(shù)據(jù)庫查出來的數(shù)據(jù)直接轉(zhuǎn)換的話是[{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },{ "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }]這樣的!
查看完整描述

2 回答

?
慕的地10843

TA貢獻(xiàn)1785條經(jīng)驗(yàn) 獲得超8個(gè)贊

其實(shí)就是把這3個(gè)結(jié)果并成一個(gè)數(shù)組,再轉(zhuǎn)就是了

例如,
$res1=mysql_query($sql1);

$res2=mysql_query($sql2);

$res3=mysql_query($sql3);

定義一個(gè)新的數(shù)組 $a = array();

將3個(gè)結(jié)果壓入這個(gè)新的數(shù)組
array_push($a,$res1);

array_push($a,$res2);

array_push($a,$res3);

最后轉(zhuǎn)義輸出
echo json_encode($a);

LZ遇到問題不要?dú)怵H呀

查看完整回答
反對(duì) 回復(fù) 2019-02-28
?
喵喔喔

TA貢獻(xiàn)1735條經(jīng)驗(yàn) 獲得超5個(gè)贊

 json和php數(shù)組 格式的互相轉(zhuǎn)換,參考如下:

  $php_json = json_encode($json_arr); //把php數(shù)組格式轉(zhuǎn)換成 json 格式的數(shù)據(jù)
  echo $php_json;
  $php_json = json_decode($php_json); //再把json格式的數(shù)據(jù)轉(zhuǎn)換成php數(shù)組
  print_r($php_json);

  json數(shù)組
  $json = '[{"id":"22","name":"33","descn":"44"}]'; //json格式的數(shù)組轉(zhuǎn)換成 php的數(shù)組
  $arr = (Array)json_decode($json);
  echo $arr[0]->id; //用對(duì)象的方式訪問



查看完整回答
反對(duì) 回復(fù) 2019-02-28
  • 2 回答
  • 0 關(guān)注
  • 1064 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)