Solr returns response in following JSON format.
{
  "responseHeader":{
    "status":0,
    "QTime":2,
    "params":{
      "indent":"on",
      "start":"0",
      "q":"*:*",
      "wt":"json",
      "version":"2.2",
      "rows":"10"}},
  "response":{"numFound":3,"start":0,"docs":[
      {
        "student_id":"AB1001",
        "student_name":[
          "John"]
    },
      {
        "student_id":"AB1002",
        "student_name":[
          "Joe"]
    },
      {
        "student_id":"AB1003",
        "student_name":[
          "Lorem"]
    }]
  }}
What will be the simple way to read student_id, student_name using PHP?
Use $obj = json_decode($yourJSONString); to convert it to an object.
Then use foreach($obj->response->docs as $doc) to iterate over the "docs".
You can then access the fields using $doc->student_id and $doc->student_name[0].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With