Question: I am trying to integrate google cloud speech API in my demo app.
What I am getting as result is below :

```
    {
    results {
      alternatives {
        transcript: "hello"
      }
      stability: 0.01
    }
}

```

Code to get response : 

```
[[SpeechRecognitionService sharedInstance] streamAudioData:self.audioData
                                                withCompletion:^(StreamingRecognizeResponse *response, NSError *error) {
                                                  if (error) {
                                                    NSLog(@"ERROR: %@", error);
                                                    _textView.text = [error localizedDescription];
                                                    [self stopAudio:nil];
                                                  } else if (response) {
                                                    BOOL finished = NO;
                                                    //NSLog(@"RESPONSE: %@", response.resultsArray);
                                                    for (StreamingRecognitionResult *result in response.resultsArray) {
                                                        NSLog(@"result : %@",result);
                                                        //_textView.text = result.alternatives.transcript;
                                                      if (result.isFinal) {
                                                        finished = YES;
                                                      }
                                                    }

                                                    if (finished) {
                                                      [self stopAudio:nil];
                                                    }
                                                  }
                                                }
     ];

```

My problem is, the response i am getting is not a proper JSON then how do i get the value of key `transcript` ? Any help would be appreciated. Thanks.

Answer: 
In terms of `string::find_last_of()`, specifying `pos` means that the search only includes characters *at or before* that position, ignoring any possible occurrences after it. If it cannot be found given those limitations, `npos` is returned.

Full details can be found in the standard, for example `C++11 21.4.7.5`:

---

> 
> **21.4.7.5 `basic_string::find_last_of` [string::find.last.of]**
> 
> 
> `size_type find_last_of(`  
> 
>      `const basic_string& str,`  
> 
>      `size_type pos = npos`  
> 
> `) const noexcept;`
> 
> 
> *Effects:* Determines the highest position `xpos`, if possible, such that both of the following conditions obtain:
> 
> 
> * `xpos <= pos` and `xpos < size()`;
> * `traits::eq(at(xpos), str.at(I))` for some element `I` of the string controlled by `str`.
> 
> 
> *Returns:* `xpos` if the function can determine such a value for `xpos`. Otherwise, returns `npos`.
> 
> 
> *Remarks:* Uses `traits::eq()`.
> 
> 
> 
> 
> ---
> 
> 
> `size_type find_last_of(`  
> 
>      `charT c,`  
> 
>      `size_type pos = npos`  
> 
> `) const noexcept;`
> 
> 
> *Returns:* `find_last_of(basic_string<charT,traits,Allocator>(1,c),pos)`.
> 
> 
> 

---

It's that `xpos <= pos` in the first bullet point that's causing the problem here. Unless your string actually *starts* with `=`, your particular expression is going to get `npos` as a result. *That's* the large number you're seeing as it's an unsigned variant of the value `-1`.

The correct form of `find_last_of()` if you want to find the last character is:

```
size_t index = str.find_last_of('=');

```

Since `pos` defaults to `npos`, meaning that it considers the *entire* string.
Second argument is wrong, try:

```
#include <string>
#include <iostream>
int main() 
{
    std::string str = "page id = 0 file = \"simsun.png\" chars count = 97";
    size_t index = str.find_last_of('=');
    std::cout << index << std::endl;
    return 0;
}

```