[SalesForce] Apex Class Error Message: System.JSONException: No content to map to Object due to end of input

I am getting an Error in Apex when i try to Deserialize the JSON Response.
System.JSONException: No content to map to Object due to end of input

My JSON Response in debug Log is:
[{"recId":"1"},{"recId":"2"}]

My Apex Class is :

public with sharing class myvalues {

 @AuraEnabled(cacheable=true)
 public static List<String> thisvalue(String searchKey , String selrec){
 system.debug('The value is '+selrec);
    If(selrec != null || selrec != ''){
    List<String> f = (List<String>) JSON.deserialize(selrec, 
      List<String>.class);
     system.debug('value of List is '+f);

     }
  }
}

What Am I missing Here?

Best Answer

The reason for your error is that selrec is not a list of strings, in Json terms, it is a list of objects, a list of strings would be ["abc","def"]

You need something like this:

class SelectRecord {
  String recId;
}

and then

  @AuraEnabled(cacheable=true)
  public static List<String> thisvalue(String searchKey , String selrec){
    system.debug('The value is '+selrec);
    If(String.isNotBlank(selRec)){
      List<SelectRecord> selectedRecs = (List<SelectRecord>) JSON.deserialize(selrec, 
         List<SelectRecord>.class);
      system.debug('value of List is '+selectedRecs);

    }
  }