我编写了一个创建geoJSON的函数,它会吐出如下结果:
{"type":"FeatureCollection","features":[{"type":"Feature","properties":{"StreetAddress":"3112 Gaddis Road, Canton, Georgia 30115","Name":"Woodmont","Bedrooms":"6-Mar","Bathrooms":"5-Feb","Garage":"2","StartPrice":"Mid $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.35505189999999,34.2319281],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"7040 Majors Road, Cumming, Georgia 30040","Name":"Ashford Manor Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2036578,34.1641024],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"977 Woodbury Road, Canton, Georgia 30114","Name":"River Green","Bedrooms":"7-Mar","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$245,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.524852,34.219029],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3983 Paul Samuel Rd NW, Kennesaw, Georgia 30152","Name":"Summerhour","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.6657365,33.9875893],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4550 Hickory Road, Holly Springs, Georgia 30115","Name":"Oakhaven","Bedrooms":"6-Mar","Bathrooms":"2.5-5","Garage":"2","StartPrice":"$272,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4282121,34.1675759],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3210 Five Forks Trickum Rd, Lilburn, Georgia 30047","Name":"Brookstone Preserve","Bedrooms":"7-Apr","Bathrooms":"6-Feb","Garage":"2","StartPrice":"High $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.06380329999999,33.8794093],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4950 Hickory Road, Woodstock, Georgia 30188","Name":"Woodhaven Court","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$252,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.420323,34.16809],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"5615 Grand Reunion Drive, Hoschton, Georgia 30548","Name":"Reunion","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$274,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-83.863038,34.114602],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"922 Wooten Lake Road, Kennesaw, Georgia 30144","Name":"Falls Crest","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5774563,34.05599],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"105 Park Haven Lane, Tyrone, Georgia 30290","Name":"River Crest","Bedrooms":"7-Apr","Bathrooms":"2.5-6.5","Garage":"3-Feb","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5801833,33.508861],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"413 Spring View Drive, Woodstock, Georgia 30188","Name":"Woodview Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3-Feb","StartPrice":"$318,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4685219,34.1075786],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1340 Terrell Mill Road, Marietta, Georgia 30067","Name":"Ivy Crest","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$341,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.46576999999999,33.9195719],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4604 Shiloh Road, Cumming, Georgia 30040","Name":"Shiloh Ridge","Bedrooms":"6-Apr","Bathrooms":"2.5-5.5","Garage":"2","StartPrice":"$357,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2027887,34.1456647],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"2750 Kimball Bridge Road , Alpharetta, Georgia 30009","Name":"The Walk at Braeden","Bedrooms":"4-Feb","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$378,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2779815,34.0626187],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1057 N Jamestown Road, Decatur, Georgia 30033","Name":"Parkside at Mason Mill - The Overlook","Bedrooms":"4-Mar","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$420,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.3031443,33.8114372],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4400 West Atlanta Road SE, Smyrna, Georgia 30080","Name":"4400 West","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$429,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.49285309999999,33.845839],"type":"Point"}}]}
无论出于何种原因,它拒绝工作,除非我进入并在我的文本编辑器中输入以打破Features数组中的每一行。严格来说,我不确定为什么会这样,或者我如何改变我的功能来编写准备复制粘贴的代码。关于这里出了什么问题的任何想法?
编辑:要清楚,当我尝试将其分配给变量并且我的JavaScript中断时,我收到一个未识别的令牌错误。我不确定为什么我会因为一个好问题而被投票,因为还没有人解决这个问题。
启用软包装然后在功能阵列的每个项目之间输入几次后,您可以看到这大约工作的一半:
为了让它完全发挥作用,我必须为每一个项目按Enter键以打破这些行。我希望我的问题现在很明确。
编辑2 - 这是我发现的与导致语法突出显示中断的错误相关的问题:bug
但是,这不应该导致JSON无效。
这是我输入所有内容后的样子:
为了让事情变得更奇怪,geojson可以正常工作,如果我把它输入到codepen中。
答案 0 :(得分:-1)
const yourJSON = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"StreetAddress":"3112 Gaddis Road, Canton, Georgia 30115","Name":"Woodmont","Bedrooms":"6-Mar","Bathrooms":"5-Feb","Garage":"2","StartPrice":"Mid $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.35505189999999,34.2319281],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"7040 Majors Road, Cumming, Georgia 30040","Name":"Ashford Manor Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2036578,34.1641024],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"977 Woodbury Road, Canton, Georgia 30114","Name":"River Green","Bedrooms":"7-Mar","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$245,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.524852,34.219029],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3983 Paul Samuel Rd NW, Kennesaw, Georgia 30152","Name":"Summerhour","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.6657365,33.9875893],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4550 Hickory Road, Holly Springs, Georgia 30115","Name":"Oakhaven","Bedrooms":"6-Mar","Bathrooms":"2.5-5","Garage":"2","StartPrice":"$272,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4282121,34.1675759],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3210 Five Forks Trickum Rd, Lilburn, Georgia 30047","Name":"Brookstone Preserve","Bedrooms":"7-Apr","Bathrooms":"6-Feb","Garage":"2","StartPrice":"High $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.06380329999999,33.8794093],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4950 Hickory Road, Woodstock, Georgia 30188","Name":"Woodhaven Court","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$252,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.420323,34.16809],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"5615 Grand Reunion Drive, Hoschton, Georgia 30548","Name":"Reunion","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$274,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-83.863038,34.114602],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"922 Wooten Lake Road, Kennesaw, Georgia 30144","Name":"Falls Crest","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5774563,34.05599],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"105 Park Haven Lane, Tyrone, Georgia 30290","Name":"River Crest","Bedrooms":"7-Apr","Bathrooms":"2.5-6.5","Garage":"3-Feb","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5801833,33.508861],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"413 Spring View Drive, Woodstock, Georgia 30188","Name":"Woodview Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3-Feb","StartPrice":"$318,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4685219,34.1075786],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1340 Terrell Mill Road, Marietta, Georgia 30067","Name":"Ivy Crest","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$341,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.46576999999999,33.9195719],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4604 Shiloh Road, Cumming, Georgia 30040","Name":"Shiloh Ridge","Bedrooms":"6-Apr","Bathrooms":"2.5-5.5","Garage":"2","StartPrice":"$357,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2027887,34.1456647],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"2750 Kimball Bridge Road , Alpharetta, Georgia 30009","Name":"The Walk at Braeden","Bedrooms":"4-Feb","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$378,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2779815,34.0626187],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1057 N Jamestown Road, Decatur, Georgia 30033","Name":"Parkside at Mason Mill - The Overlook","Bedrooms":"4-Mar","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$420,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.3031443,33.8114372],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4400 West Atlanta Road SE, Smyrna, Georgia 30080","Name":"4400 West","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$429,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.49285309999999,33.845839],"type":"Point"}}]};
const prettyFormat = JSON.stringify(yourJSON, null, 2);
document.querySelector('#inJSON')
.innerText = JSON.stringify(yourJSON);
document.querySelector('#outJSON')
.innerText = JSON.stringify(yourJSON, null, 2);
<h3>RAW:</h3>
<pre id="inJSON"></pre>
<h3>Formatted:</h3>
<pre id="outJSON"></pre>
如何使用JSON.stringify?
const yourJSON = {"type":"FeatureCollection","features":[{"type":"Feature","properties":{"StreetAddress":"3112 Gaddis Road, Canton, Georgia 30115","Name":"Woodmont","Bedrooms":"6-Mar","Bathrooms":"5-Feb","Garage":"2","StartPrice":"Mid $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.35505189999999,34.2319281],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"7040 Majors Road, Cumming, Georgia 30040","Name":"Ashford Manor Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2036578,34.1641024],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"977 Woodbury Road, Canton, Georgia 30114","Name":"River Green","Bedrooms":"7-Mar","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$245,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.524852,34.219029],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3983 Paul Samuel Rd NW, Kennesaw, Georgia 30152","Name":"Summerhour","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3","StartPrice":"$375,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.6657365,33.9875893],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4550 Hickory Road, Holly Springs, Georgia 30115","Name":"Oakhaven","Bedrooms":"6-Mar","Bathrooms":"2.5-5","Garage":"2","StartPrice":"$272,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4282121,34.1675759],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"3210 Five Forks Trickum Rd, Lilburn, Georgia 30047","Name":"Brookstone Preserve","Bedrooms":"7-Apr","Bathrooms":"6-Feb","Garage":"2","StartPrice":"High $300s","Soldout":"FALSE"},"geometry":{"coordinates":[-84.06380329999999,33.8794093],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4950 Hickory Road, Woodstock, Georgia 30188","Name":"Woodhaven Court","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$252,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.420323,34.16809],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"5615 Grand Reunion Drive, Hoschton, Georgia 30548","Name":"Reunion","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"2","StartPrice":"$274,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-83.863038,34.114602],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"922 Wooten Lake Road, Kennesaw, Georgia 30144","Name":"Falls Crest","Bedrooms":"4-Feb","Bathrooms":"3-Feb","Garage":"2","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5774563,34.05599],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"105 Park Haven Lane, Tyrone, Georgia 30290","Name":"River Crest","Bedrooms":"7-Apr","Bathrooms":"2.5-6.5","Garage":"3-Feb","StartPrice":"$292,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.5801833,33.508861],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"413 Spring View Drive, Woodstock, Georgia 30188","Name":"Woodview Enclave","Bedrooms":"7-Apr","Bathrooms":"2.5-6","Garage":"3-Feb","StartPrice":"$318,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.4685219,34.1075786],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1340 Terrell Mill Road, Marietta, Georgia 30067","Name":"Ivy Crest","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$341,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.46576999999999,33.9195719],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4604 Shiloh Road, Cumming, Georgia 30040","Name":"Shiloh Ridge","Bedrooms":"6-Apr","Bathrooms":"2.5-5.5","Garage":"2","StartPrice":"$357,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2027887,34.1456647],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"2750 Kimball Bridge Road , Alpharetta, Georgia 30009","Name":"The Walk at Braeden","Bedrooms":"4-Feb","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$378,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.2779815,34.0626187],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"1057 N Jamestown Road, Decatur, Georgia 30033","Name":"Parkside at Mason Mill - The Overlook","Bedrooms":"4-Mar","Bathrooms":"2-3.5","Garage":"2","StartPrice":"$420,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.3031443,33.8114372],"type":"Point"}},{"type":"Feature","properties":{"StreetAddress":"4400 West Atlanta Road SE, Smyrna, Georgia 30080","Name":"4400 West","Bedrooms":"4-Mar","Bathrooms":"2.5-3.5","Garage":"2","StartPrice":"$429,990 ","Soldout":"FALSE"},"geometry":{"coordinates":[-84.49285309999999,33.845839],"type":"Point"}}]};
const prettyFormat = JSON.stringify(yourJSON, null, 2);