Edit:
SFDCFox's answer explains why the standard method with the same name does not work in your case. Basically, getPopulatedFieldsAsMap() only works on SObject and it's derivatives. Since you're using a custom class, you need to define it for yourself.
Answer:
The answer to your question is pretty straight forward. You're calling a method that doesn't exist. The class definition for Accounts does not have a method called getPopulatedFieldsAsMap() defined for it.
You also have a list named accounts and a class named accounts. You should, even if for nothing more than code readability, change your class name to account and your list can stay accounts.
You'll need to define your method in order to use it:
public class searchClass {
public Integer item_count;
public List<Accounts> accounts;
public class Account {
public String account_number;
public String new_id;
public String record_type_id;
public String account_type;
/* Define your method here */
public Map<String, Object> getPopulatedFieldsAsMap() {
Map<String, Object> result = new Map<String, Object>();
result.put('account_number', this.account_number);
/* rinse and repeat */
return result;
}
}
public static searchClass parse(String json) {
return (searchClass) System.JSON.deserialize(json, searchClass.class);
}
}
Then:
SearchClass sclass = SearchClass.parse(jsonStr);
for (SearchClass.Account a : sclass.accounts) {
Map<String, Object> fieldToValue = a.getPopulatedFieldsAsMap();
for (String key : fieldToValue.keySet()) {
system.debug(key + '->' + fieldToValue.get(key));
}
}
Edit:
Also keeping in mind with what SFDCFox said regarding wanting to use a map. Lets go one more step further and assume you want to de-dupe your account list. The below will automatically build a map of unique accounts (sort of but lets not get too far away from the question here).
SearchClass sclass = SearchClass.parse(jsonStr);
Map<String, SearchClass.Account> accountMap = new Map<String, SearchClass.Account>();
for (SearchClass.Account a : sclass.accounts) {
accountMap.put(a.Account_Number, a);
}
Final Note:
If you haven't already heard of / played with it; JSON2Apex is a pretty sweet tool.
Update:
To answer the question in the comments
If you're trying to compare two accounts you'd need something like this:
Map<String, Map<String, Object>> accountsMap = new Map<String, Map<String, Object>>();
for (SearchClass.Account a : sclass.accounts) {
accountsMap.put(a.Account_Number, a.getPopulatedFieldsAsMap());
}
if (accountsMap.get('Account#1').get('FieldKey') == accountsMap.get('Account#2').get('FieldKey')) {
//Do Something
}
This is just one way to do it. You could use a list instead of a map and index them using the [] operator as well but that would give you no way to know which 2 accounts you are comparing (and will result in extremely inefficient code at the very least).
Also, it seems like the big problem you're having is that you don't really understand the basic data structures and how they work. These structures are not restricted to APEX and appear in many different programming languages and the syntax is the same as most C derivatives.
The best advice I can give you is to be honest with your boss about your experience as a developer. Otherwise you're in for a very long and hard project and you can expect a lot of backlash from the stackexchange community if you keep asking questions like this one.