JavaScript中遍历JSON对象,获取所有的键Key及对应的值Value

2017年11月06日 其他资源 8条评论 阅读3803次


JavaScript中遍历JSON对象,打印所有的键Key及值Value。


var obj = {"key1":"val1", "key2":"val2"};
var str = "";
for (var p in obj) {
    str = str + (p + " = " + obj[p]) + ", ";
}
console.log(str);


遍历JSON对象后输出的键值字符串为:

key1 = val1, key2 = val2, 

分享本文至:

WRITTEN BY

avatar
本文标签:jsonJavaScript
看了本文是不是觉得很赞,那就赶紧点击下面按钮分享给身边的朋友吧!

8 条评论

  1. avatar adharaweb

    <a href="http://www.adanastarpen.com/nike-air-max-tailwind-8-dam%C3%A4nner-rosa-silber-schuhej">nike air max tailwind 8 dam盲nner rosa silber</a> <a href="http://www.actconfident.com/minnesota-timberwolves-47-nba-after-glow-cap-hath">minnesota timberwolves 47 nba after glow cap</a> <a href="http://www.erzurumihl.com/kyrie-1-chaussures-bleu-chaussuresh">kyrie 1 chaussures bleu</a> <a href="http://www.candctowingil.com/nike-flyknit-lunar-3-femminile-grigio-nero-scarpeq">nike flyknit lunar 3 femminile grigio nero</a> <a href="http://www.onlysidekick.com/air-jordan-retro-3-womens-green-mint-green-shoesj">air jordan retro 3 womens green mint green</a> <a href="http://www.rmmassage.com/air-jordan-13-retro-lilla-skoi">air jordan 13 retro lilla</a>
    adharaweb http://www.adharaweb.com/

  2. avatar julides

    <a href="http://www.xgaajgeg.com/grey-nike-air-max-shoes-shoesk">grey nike air max shoes</a> <a href="http://www.bisnistrading.com/nike-acg-air-max-goadome-gr%C3%B8n-skoj">nike acg air max goadome gr酶n</a> <a href="http://www.axxisdrilling.com/nike-dunk-sky-hi-dark-grau-schuheh">nike dunk sky hi dark grau</a> <a href="http://www.bunqdesktop.com/nike-air-max-2016-women-orange-grey-blue-black-shoesk">nike air max 2016 women orange grey blue black</a> <a href="http://www.iamsubscribed.com/michael-kors-tan-crossbody-mkh">michael kors tan crossbody</a> <a href="http://www.bcstormwater.com/nike-air-force-1-grau-oransje-obuvi">nike air force 1 grau oransje</a>
    julides http://www.julides.com/

  3. avatar erstube

    <a href="http://www.mwartsdrama.com/nike-zoom-winflo-3-vert-rouge-chaussuresh">nike zoom winflo 3 vert rouge</a> <a href="http://www.meshmotors.com/prada-mens-crossection-knit-tech-leather-sneakers-pradah">prada mens crossection knit tech leather sneakers</a> <a href="http://www.aspenmedisys.com/los-angeles-dodgers-grey-jersey-nfli">los angeles dodgers grey jersey</a> <a href="http://www.smartiesland.com/nike-kd-8-bl%C3%A5-s%C3%B8lv-skoq">nike kd 8 bl氓 s酶lv</a> <a href="http://www.emcetolerie.com/mens-long-sleeve-polo-xxl-poloh">mens long sleeve polo xxl</a> <a href="http://www.lapaktoko.com/air-jordan-ultra-fly-white-grey-shoesi">air jordan ultra fly white grey</a>
    erstube http://www.erstube.com/

  4. avatar candacebenson

    <a href="http://www.candacebenson.com/adidas-rose-or-chaussures-zx-flux-kurpesd">adidas rose or chaussures zx flux</a> <a href="http://www.kodakid.com/nike-air-zoom-vomero-9-blau-schuhec">nike air zoom vomero 9 blau</a> <a href="http://www.brantfordpark.com/jordan-bel-air-grau-schwarz-butyg">jordan bel air grau schwarz</a> <a href="http://www.landsmanbook.com/adidas-eqt-enfants-chaussures-violet-gris-scarpec">adidas eqt enfants chaussures violet gris</a> <a href="http://www.moviestellar.com/mujeres-supra-skytop-rojo-cielo-azul-chaussuresf">mujeres supra skytop rojo cielo azul</a> <a href="http://www.djprofi.com/nike-air-max-tailwind-8-guld-s%C3%B8lv-butya">nike air max tailwind 8 guld s酶lv</a>
    candacebenson http://www.candacebenson.com/

  5. avatar seonnagittens

    <a href="http://www.seansinjin.com/nike-lunarglide-8-le-gull-restaurant-obuvd">nike lunarglide 8 le gull restaurant</a> <a href="http://www.varsitystance.com/nike-lunarglide-femminile-wide-scarpec">nike lunarglide femminile wide</a> <a href="http://www.azuraonline.com/nike-kyrie-2-herren-schuhe-list-kurpesb">nike kyrie 2 herren schuhe list</a> <a href="http://www.brodiebaranow.com/cubs-44-anthony-rizzo-white-strip-home-cooperstown-stitched-mlb-jersey-nflr">cubs 44 anthony rizzo white strip home cooperstown stitched mlb jersey</a> <a href="http://www.companiens.com/dam%C3%A4nner-nike-flyknit-lunar-3-schwarz-blau-butyg">dam盲nner nike flyknit lunar 3 schwarz blau</a> <a href="http://www.cuixinyuphoto.com/bayern-munchen-3-way-fidget-spinner-g124gray-nflz">bayern munchen 3 way fidget spinner g124gray</a>
    seonnagittens http://www.seonnagittens.com/

  6. avatar evelpa

    <a href="http://www.romoautocare.com/lebron-13-yellow-shoesk">lebron 13 yellow</a> <a href="http://www.industrialegy.com/nike-air-max-95-kvinners-gull-gr%C3%A5-obuvq">nike air max 95 kvinners gull gr氓</a> <a href="http://www.bewustvitaal.com/nike-kobe-9-krm-sort-mamba-skoj">nike kobe 9 krm sort mamba</a> <a href="http://www.flushandhunt.com/nike-shox-deliver-cielo-blu-argento-scarpeq">nike shox deliver cielo blu argento</a> <a href="http://www.kendalfewster.com/nike-kd-8-womens-grey-green-shoesj">nike kd 8 womens grey green</a> <a href="http://www.gisusalon.com/nike-air-max-zero-triple-hvid-skop">nike air max zero triple hvid</a>
    evelpa http://www.evelpa.com/

  7. avatar tekmenu

    <a href="http://www.kaliteankara.com/nike-hyperdunk-2015-black-and-gold-shoesj">nike hyperdunk 2015 black and gold</a> <a href="http://www.bagsbeat.com/herren-nike-air-max-1-orange-shoesl">herren nike air max 1 orange</a> <a href="http://www.lolalolincoln.com/lavender-polo-shirt-poloh">lavender polo shirt</a> <a href="http://www.buycharboleps.com/nike-elastico-superfly-ic-sort-gr%C3%A5-hvid-skok">nike elastico superfly ic sort gr氓 hvid</a> <a href="http://www.androidsmith.com/nike-air-huarache-schwarz-carbon-soot-schuheh">nike air huarache schwarz carbon soot</a> <a href="http://www.oheyewear.com/2018-nike-air-max-air-max-2018-red-navy-blue-shoesk">2018 nike air max air max 2018 red navy blue</a>
    [url=http://www.tekmenu.com/]tekmenu[/url]

  8. avatar shoesilove

    <a href="http://www.munchstrom.net/nike-lunarglide-8-gris-naranja-blanco-butyc">nike lunarglide 8 gris naranja blanco</a> <a href="http://www.mycouponexpert.net/lebron-13-rojo-and-blanco-scarpeb">lebron 13 rojo and blanco</a> <a href="http://www.mydxp.net/adidas-pr%C3%B8dator-roll-finger-goalkeeper-gloves-kurpesf">adidas pr酶dator roll finger goalkeeper gloves</a> <a href="http://www.myersmotors.net/air-jordan-retro-12-barn-s%C3%B8lv-brun-scarpea">air jordan retro 12 barn s酶lv brun</a> <a href="http://www.mysaltwatersandal.net/salomon-gcs-athletic-trail-grau-orange-obuvb">salomon gcs athletic trail grau orange</a> <a href="http://www.nadinesproperties.net/zx-flux-techfit-blu-chaussuresd">zx flux techfit blu</a>
    shoesilove http://www.shoesilove.net/

欢迎留言




用户登录

sitemap