How to get the cart contents from $woocommerce variable?

if($woocommerce->cart->cart_contents != “”)
{
foreach( $woocommerce->cart->cart_contents as $keyoff => $book )
{
print_r($woocommerce->cart->cart_contents[$keyoff]);
print_r($book[‘quantity’]);

}
}