Facebook Interview Question for SDE1s


Country: United States




Comment hidden because of low score. Click to expand.
0
of 0 vote

Allowed to use language's json parser or have to manually create our own?

- tnutty2k8 August 03, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

Of course, manually.

- sri November 26, 2017 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess it means that JSON parser (like JSON-P) should be used and there are 3 ways to implement that like object model (with common switch and tracking the value type or via tracking the type of object) or via streaming model.

- Mike L August 14, 2017 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

public static void jsonToMap(String t) throws JSONException {

HashMap<String, String> map = new HashMap<String, String>();
JSONObject jObject = new JSONObject(t);
Iterator<?> keys = jObject.keys();

while( keys.hasNext() ){
String key = (String)keys.next();
String value = jObject.getString(key);
map.put(key, value);

}

System.out.println("json : "+jObject);
System.out.println("map : "+map);
}

- seenu.622 March 19, 2018 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Or if we don't want to use JSONObject library, we can write in the following way.

String tempJson = "{\"incomePhone\":\"213121122\",\"clientId\":\"1001\",\"clientAccountManager\":\"Gestor de Conta 1\",\"clientRetailBranch\":\"100\",\"phoneAccountManager\":\"7800100\"}";
System.out.println(tempJson);

String[] parts = tempJson.split(",");
HashMap<String,String> jsonHash = new HashMap<String,String>();

for(int i=0;i<parts.length;i++){
parts[i] = parts[i].replace("\"", "");
parts[i] = parts[i].replace("{", "");
parts[i] = parts[i].replace("}", "");
String[] subparts = parts[i].split(":");
jsonHash.put(subparts[0],subparts[1]);
}

- seenu.622 March 19, 2018 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More