0

I have an API which handles call back event of HelloSign. I get Stream in the request data. I convert that Stream into String using following code and it provide me following string.

public bool HSEventCallback(Stream stream)
{
    bool callbackStatus = false;
    try
    {
        StreamReader reader = new StreamReader(stream);
        string text = reader.ReadToEnd();

        callbackStatus = true;
    }
    catch (Exception ex)
    {
        callbackStatus = false;
    }
    return callbackStatus;
}

Result

------------------------------5sdf54df6a5s4df6 Content-Disposition: form-data; name="json"

{"event":{"event_type":"callback_test","event_time":"514651651","event_hash":"65a65adsxv34adsv514dv6514v6s584v6a5v46a5sv46sd5v146v54s6av4s6av54ds6v46av","event_metadata":{"related_signature_id":null,"reported_for_account_id":"564as4df65a4f65sd4f65sad4f6sad5f46sdf54s6df54","reported_for_app_id":null,"event_message":null}}} ------------------------------5sdf54df6a5s4df6--

Can anybody please suggest me how to de serialize above string. I can deserialize by replacing some of text and by creating class of `event'. But I don't know whether it will work for all kind of data.

Please suggest standard way to deserialize above string.

Nanji Mange
  • 2,155
  • 4
  • 29
  • 63
  • I would cut everything before the 1st `{` and after the last `}` and then do a `JsonConvert.DeserializeObject`. It might be easier if you could get a more specialized stream that could give you the body/content directly, though. – Markus Deibel Nov 29 '19 at 06:01
  • @MarkusDeibel I agree but I think there should be standard way in `C#` to get `json` only from this string. I am looking for that. – Nanji Mange Nov 29 '19 at 06:03
  • https://gist.github.com/acamino/51ae7fa45708bc1e8bcda5657374aa48 might help, but also here the stream depends on how the request was made. – Markus Deibel Nov 29 '19 at 06:07
  • This is the value you get in`text` variable? – Chetan Nov 29 '19 at 06:09
  • @ChetanRanpariya Yes, it is string – Nanji Mange Nov 29 '19 at 07:58

0 Answers0