Before Jesus says this:
“Ask ye, and it shall be given to you; seek ye, and ye shall find; knock ye, and it shall be opened to you. For each that asketh, taketh; and he that seeketh, findeth; and it shall be opened to him, that knocketh;”
He says not to throw your pearls to swine in case you are trampled to death by them or torn to pieces by wild dogs.
Before He warns of throwing yourself away, He warns not to judge others.
After He says to ask, seek, and knock, He reminds that God does not give bad things to His people, but only good things. Just as a parent does not give stones to hungry children, so God does not give worthless things to His children.
So, stop judging. Use discernment instead. And ask for what’s good, fully expecting to receive it. Seek it out so you find it. Knock and go in.