Fix dangling pointer bug in JsonRpc::invoke()

The callback parameter to invoke was a raw pointer, no way to ensure
that it won't get used after deletion (and no way to unregister the
callback.)

Changed it to an std::weak_ptr. Only the weak_ptr is stored, so if a
response is received after deletion the callback will not be invoked.