[英]How would I split this string?
How would I go about cutting this giant string? 我将如何切割这根巨大的弦? I need the data of the
first ID
," preferably for the string output to be: 我需要
first ID
的数据”,最好将字符串输出为:
"id":1,"name":"site1","has_doneit":true,"destination":"4613"
Is this possible? 这可能吗? Or if not any other ways of grabbing the name:"site1" and the has_doneit:true would be perfectly fine.
或者,如果没有其他方法来获取名称:“ site1”和has_doneit:true,则完全可以。
{"needs_complete":true,"has_done":true,"sites":[
{"id":1,"name":"site1","has_doneit":true,"destination":"4613"},{"id":2,"name":"site2","has_doneit":true,"destination":"4613"},{"id":3,"name":"site3","has_doneit":true,"destination":"4339"},{"id":4,"name":"site4","has_doneit":true,"destination":"4340"},{"id":5,"name":"site5","has_doneit":true,"destination":"4341"},
{"id":6,"name":"site6","has_doneit":true,"destination":"4622"},{"id":7,"name":"site7","has_doneit":true,"destination":"4623"},{"id":8,"name":"site8","has_doneit":true,"destination":"4828"},
{"id":9,"name":"site9","has_doneit":true,"destination":"4829"},{"id":10,"name":"site10","has_doneit":true,"destination":"4861"}]}
That seems like a JSON string so use a Json Parser... 这似乎是一个JSON字符串,所以请使用Json Parser ...
$parsedStr = json_decode($yourString, true);
you can access sites array in $parsedStr['sites']
您可以在
$parsedStr['sites']
访问站点数组
So, to access the id of the first site: 因此,要访问第一个站点的ID:
echo $parsedStr['sites'][0]['id'];
check this answer in SO Decoding JSON String in Java 在Java中解码JSON字符串中检查此答案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.