联系我们

为客户提供超预期的高品质网站设计!

js操作json对象

2020-2-25 0:00:00

<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1" />
 
</head>
<body>

//该案例用户上海车务网的优化
<script>
//定义一个json对象,变量名称为jsonstr

//k1是两地范围的开始数

//k2是两地距离的结束数

//k1-k2是随机数,表示距离多少公里

jsonstr={
    "sheng": "黑龙江",
    "k1":2000,
    "k2":2800,
    "data": [
        {
        "shi":"牡丹江",
        "pai":"黑C",
        "xian":["牡丹江市","东安区","阳明区","爱民区","西安区","东宁市","林口县","绥芬河市","海林市","宁安市","穆棱市"]
        },
        {
        "shi":"佳木斯",
        "pai":"黑D",
        "xian":["站前街道","桥南街道","建国街道","友谊街道","同江镇","城关街道","抚远镇","桦南镇","悦来镇","汤原镇"]
        },
        {
        "shi":"大庆",
        "pai":"黑E",
        "xian":["大庆市","萨尔图区","龙凤区","让胡路区","红岗区","大同区","肇州县","肇源县","林甸县","杜尔伯特蒙古族自治县"]
        },
        {
        "shi":"鸡西",
        "pai":"黑G",
        "xian":["鸡冠区","恒山区","滴道区","梨树区","城子河区","麻山区","虎林市","密山市","鸡东县"]
        },
        {
        "shi":"双鸭山",
        "pai":"黑J",
        "xian":["尖山区","岭东区","四方台区","宝山区","集贤县","友谊县","宝清县","饶河县"]
        },
        {
        "shi":"伊春",
        "pai":"黑F",
        "xian":["伊春区","南岔区","友好区","西林区","翠峦区","新青区","美溪区","金山屯区","五营区","乌马河区","汤旺河区","带岭区","乌伊岭区","红星区","上甘岭区","嘉荫县","铁力市"]
        },
        {
        "shi":"七台河市",
        "pai":"黑K",
        "xian":["桃山区","新兴区","茄子河区","勃利县"]
        },
        {
        "shi":"鹤岗",
        "pai":"黑H",
        "xian":["向阳区","工农区","南山区","兴安区","东山区","兴山区","萝北县","绥滨县"]
        },
        {
        "shi":"黑河",
        "pai":"黑N",
        "xian":["爱辉区","北安市","五大连池市","嫩江市","孙吴县","逊克县"]
        },
        {
        "shi":"绥化",
        "pai":"黑M",
        "xian":["绥化市","北林区","望奎县","兰西县","青冈县","庆安县","明水县","绥棱县","安达市","肇东市","海伦市"]
        },
        {
        "shi":"大兴安岭地区",
        "pai":"黑P",
        "xian":["加格达奇区","松岭区","呼中区","新林区","漠河市","呼玛县","塔河县"]
        },
        ]
};

//alert(Object.keys(jsonstr).length);

//var length=Object.keys(jsonstr).length;
//document.write(jsonstr["sheng"]);
var xian=jsonstr["data"];
var xianLength=xian.length;
for(x=0;x<xianLength;x++)
{
        
        document.write("<span style='color: rgb(255, 0,  0);'><strong>上海上外地牌照"+jsonstr["sheng"]+xian[x]["shi"]+xian[x]["pai"]+"牌照   专业代办<br>");
        document.write(xian[x]["pai"]+"上牌热线 :13601702302  小钟</strong></span><br/><p><br/></p>");
       document.write("2020年上海户口人新旧车上外地牌照"+jsonstr["sheng"]+xian[x]["shi"]+"【"+xian[x]["pai"]+"车牌】<br>");
       document.write("<strong><span style='font-size:  24px;'>一、上海户口新车旧车办外地牌照"+jsonstr["sheng"]+xian[x]["shi"]+"【"+xian[x]["pai"]+"车牌】行情:</span></strong><br/>");
       var dijishi="";
       var dijishi=xian[x]["xian"];
       var dijishilength=dijishi.length;
       for(y=0;y<dijishilength;y++){
       var day=randomNum(2,10);
       var kms=randomNum(jsonstr["k1"],jsonstr["k2"]);
        document.write(dijishi[y]+"【"+xian[x]["pai"]+"车牌】"+dijishi[y]+"距上海"+kms+"多公里,"+day+"天左右办好;<br>");
       }
       
        document.write("<p><br/></p><strong><span  style='font-size:  24px;'>二、办外地牌照"+jsonstr["sheng"]+xian[x]["shi"]+"【"+xian[x]["pai"]+"车牌】需要材料和机动车手续:</span></strong><br>");
        document.write("1)车架号拓印,发动机拓印号<br>");
        document.write("2)上海户口新车旧车机动车交通事故责任强制保险单副本<br>");
        document.write("3)上海户口新车旧车纳税申报表<br>");
        document.write("4)上海户口新车旧车车辆一致性证书<br>");
        document.write("5)车主本人身份证<br>");
        document.write("6)上海户口新车旧车车辆合格证原件(进口车提供进口关单证明)<br>");
        document.write("7)上海户口新车旧车发票三联(发票联、报税联、注册登记联)<br>");
        document.write("8)原车照片两张<br>");
         document.write("<p><br/></p><strong><span  style='font-size:  24px;'>三、"+jsonstr["sheng"]+xian[x]["shi"]+"【"+xian[x]["pai"]+"车牌】介绍</span></strong><br>");
        document.write("<p></p><p>文字</p>");
        
        document.write("<p></p><p>############################</p>");
        document.write("<p></p><p>############################</p>");
}


function randomNum(minNum, maxNum) {
  switch (arguments.length) {
    case 1:
      return parseInt(Math.random() * minNum + 1, 10);
      break;
    case 2:
      return parseInt(Math.random() * ( maxNum - minNum + 1 ) + minNum, 10);
      //或者 Math.floor(Math.random()*( maxNum - minNum + 1 ) + minNum );
      break;
    default:
      return 0;
      break;
  }
}

</script>



</body>
</html>


上一条新闻:青浦小程序开发,小程序轮播案例2
下一条新闻:seajs加载jquery实例

 

4008-520-214 54057491 info@maolian.net