【问题标题】:How would I split this string?我将如何拆分这个字符串?
【发布时间】:2014-11-23 06:35:32
【问题描述】:

我将如何剪断这条巨大的绳子?我需要 first ID," 的数据,最好是字符串输出:

"id":1,"name":"site1","has_doneit":true,"destination":"4613"

这可能吗?或者,如果没有其他获取名称的方法:“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"}]}

【问题讨论】:

  • 带有 JSON 解析器。不要尝试使用split 或正则表达式来处理这类事情。

标签: java javafx javafx-8


【解决方案1】:

这似乎是一个 JSON 字符串,所以请使用 Json Parser...

PHP:JSON_decode

$parsedStr = json_decode($yourString, true);

您可以访问$parsedStr['sites']中的站点数组

所以,要访问第一个站点的 id:

echo $parsedStr['sites'][0]['id'];

Java

在 SO Decoding JSON String in Java 中检查这个答案

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-05
    • 2022-09-27
    • 1970-01-01
    • 2012-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多