简体   繁体   中英

How to search through a JSON?

I'm trying to search through this Json array using PHP:

{"count":"2","items":{"milestone":[{"id":"3107","username":"TomSmith1","userid":"1620602","date":"2012-01-12 16:49:26","projectid":"804","projectname":"TEST PROJECT","reason":"Partial payment for project","amount":"25","currency":"1"},{"id":"3111","username":"HarryCole","userid":"1620603","date":"2012-01-13 16:42:39","projectid":"804","projectname":"TEST PROJECT 2","reason":"Partial payment for project","amount":"10","currency":"1"}]}}

I want to search through this to find the "id", which has the project name "TEST PROJECT 2" and the username "HarryCole". I've attempted this using a foreach loop but haven't succeeded. Can anyone point me in the right direction? Thanks.

您想在字符串上使用json_decode($json, true)将其从JSON转换为PHP表示法(关联数组)。

You're going to need http://us2.php.net/json_decode and also a foreach loop like

foreach($json_decoded as $key=>$value) {
     // Check for id / values
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM