我正在尝试使用PHP搜索这个Json数组:
{"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"}]}}
我想通过搜索来查找“id”,其项目名称为“TEST PROJECT 2”,用户名为“HarryCole”。我尝试使用foreach
循环,但没有成功。谁能指出我正确的方向?感谢。
答案 0 :(得分:2)
您希望在字符串上使用json_decode($json, true)
将其从JSON转换为PHP表示法(关联数组)。
答案 1 :(得分:1)
你需要http://us2.php.net/json_decode以及像
这样的foreach循环foreach($json_decoded as $key=>$value) {
// Check for id / values
}