This is the Script and i send 10 to the function this the output:
State 10
State -
So, i send a json sting with some data. The string gets read and the data is there, but only in the if{}.
I don't know, why my variable "print_state" is not available in the complete function.
You are re-declaring "print_state" as a local variable in your "if" statement. Remove the preceeding "String" from "print_state" in the "if" block and you're good.
And another note: Do not use the String class at all
If you define a variable within an IF statement it no longer exists when the IF statement completes.
I wonder if you are unintentionally creating a local variable with the same name as a global variable. When you prefix a variable name with String (or char or int) it tells the compiler to create a new variable. If you just want to use an existing variable don't use the prefix.
Alternatively, create the variable before the IF statement.
Separately ...
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.