Skip to main content

How to read arrays from json

I'm new to json and will appreciate help with this. I have a json string looking like:

{"success":1,"pager":{"page":1,"per_page":250,"total":1813},"results":[{"Id":202322021,"SportId":4,"SportName":"Football","RegionId":31,"RegionName":"Turkey","LeagueId":102729,"LeagueName":"Turkiye Kupasi","BetRadarId":29664196,"our_event_id":4157451,"IsPreMatch":true,"Date":"2021-10-27T17:45:00Z","updated_at":"1635354806","HomeTeam":"Kayserispor","HomeTeamId":230391,"AwayTeam":"Artvin Hopaspor","AwayTeamId":228914,"Markets":[],"optionMarkets":[{"properties":[],"comboPrevention":"NoFixtureCombo","templateCategory":{"category":"Gridable","id":0},"status":"Visible","isMain":true,"grouping":{"gridGroups":["ls8o6ll2v"],"detailed":[{"name":"Match Result","marketTabId":1,"marketHelpPath":"Football\/Match Result (Regular Time)","index":7930,"displayType":"Regular","group":0}],"parameters":{"marketType":"ThreeWay","period":"RegularTime","happening":"Goal"}},"id":29622716,"name":{"value":"Match Result","sign":"9Vlc5w=="},"minCombo":1,"options":[{"name":{"value":"Kayserispor","sign":"tyg4wg=="},"id":96896088,"sourceName":{"value":"1"},"status":"Visible","price":{"id":145532907,"odds":1.055,"americanOdds":-2000,"denominator":18,"numerator":1}},{"price":{"id":145532911,"odds":11,"americanOdds":1000,"numerator":10,"denominator":1},"status":"Visible","name":{"value":"X","sign":"JHhicw=="},"id":96896089},{"price":{"id":145532915,"odds":31,"americanOdds":3000,"numerator":30,"denominator":1},"status":"Visible","sourceName":{"value":"2"},"id":96896090,"name":{"value":"Artvin Hopaspor","sign":"2ruL4g=="}}],"parameters":[{"key":"Happening","value":"Goal","type":"String"},{"key":"MarketType","value":"3way","type":"String"},{"type":"String","value":"RegularTime","key":"Period"}]},{"minCombo":1,"id":29622721,"name":{"value":"Double Chance","sign":"WRDxhg=="},"parameters":[{"key":"Happening","type":"String","value":"Goal"},{"key":"MarketType","value":"DoubleChance","type":"String"},{"type":"String","value":"RegularTime","key":"Period"}],"options":[{"status":"Suspended","price":{"odds":1,"id":145532955},"id":96896100,"name":{"sign":"YrFHYg==","value":"Kayserispor or X"}},{"name":{"value":"X or Artvin Hopaspor","sign":"knPxTA=="},"id":96896101,"status":"Visible","price":{"americanOdds":825,"denominator":4,"numerator":33,"id":145532959,"odds":9.25}},{"price":{"id":145532963,"odds":1.04,"americanOdds":-2500,"numerator":1,"denominator":25},"status":"Visible","name":{"sign":"fwDTwg==","value":"Kayserispor or Artvin Hopaspor"},"id":96896102}],"comboPrevention":"NoFixtureCombo","properties":[],"isMain":false,"status":"Visible","templateCategory":{"id":0,"category":"Gridable"},"grouping":{"parameters":{"period":"RegularTime","marketType":"DoubleChance","happening":"Goal"},"detailed":[{"marketTabId":1,"name":"Double Chance","group":0,"displayType":"Regular","marketHelpPath":"Football\/Double Chance","index":17230}],"gridGroups":["e8vi2hdwz"]}},{"options":[{"price":{"numerator":87,"denominator":100,"americanOdds":-115,"odds":1.87,"id":155223689},"status":"Visible","name":{"sign":"5Rageg==","value":"Over 3,5"},"id":100328998},{"price":{"numerator":5,"denominator":6,"americanOdds":-120,"odds":1.83,"id":155223693},"status":"Visible","id":100328999,"name":{"value":"Under 3,5","sign":"KP8xUw=="}}],"parameters":[{"type":"Decimal","value":"3.5000","key":"DecimalValue"},{"key":"Happening","value":"Goal","type":"String"},{"type":"String","value":"Over\/Under","key":"MarketType"},{"key":"Period","type":"String","value":"RegularTime"}],"name":{"value":"Total Goals","sign":"Y9HR2w=="},"id":30811485,"minCombo":1,"spread":0.04,"grouping":{"parameters":{"period":"RegularTime","marketType":"OverUnder","attr":"3.5000","happening":"Goal","attrType":"Decimal"},"detailed":[{"name":"Over\/Under Total Goals","marketTabId":1,"subIndex":4,"displayType":"OverUnder","index":27330,"group":0},{"subIndex":4,"marketTabId":1,"group":0,"displayType":"OverUnder","index":35130},{"group":2,"displayType":"OverUnder","index":11730,"subIndex":4,"marketTabId":1,"name":"Over\/Under Total Goals"},{"index":19530,"displayType":"OverUnder","group":2,"marketTabId":1,"subIndex":4}],"gridGroups":["tabpo1c9n"]},"balanced":1,"status":"Visible","attr":"3,5","isMain":false,"templateCategory":{"category":"Gridable","id":0},"properties":[],"comboPrevention":"NoFixtureCombo"}]},

I am able to read the straight forward data such as HomeTeam, AwayTeam, Date using the following php code:

  <?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
$mk=0;
$json=file_get_contents('https://api.b365api.com/v1/bwin/prematch?token=TOKEN-KEY');
$json_data=json_decode($json,true);

foreach ($json_data['results'] as $key => $value) 
{
if ($value['SportName']=="Football")
    {
        echo "HomeTeam ".$value['HomeTeam']."  ";
        echo "AwayTeam ".$value['AwayTeam']."<br>";
    echo "LeagueName ".$value['LeagueName']."   ".$value['Date']."<br>";
    
    foreach ($value['optionMarkets'] as $keyy => $val)
{
echo "val ".$val;
}

}
}
?>

I will like to read the data from "optionMarkets": to the end. Any help will be appreciated. Thanks.



source https://stackoverflow.com/questions/69743663/how-to-read-arrays-from-json

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data