0

This is part two of my problem here. Thanks to you guys I was able to get variables to work correctly to split data out to a jSON string. Now, I need to filter the JSON data to get a result.

For example: if the JSON file gets this data:

 {"shapeID":"diamond","data1":"pants","data2":"shirt"} it outputs:

  {"result":"Cool Outfit"}

so depending on the combination of data1 and data2 the result is generated.

I have no idea on where to start. But I do have the JSON string

thank you for your time.

1
  • Well, what rules do you want to use? What leads to the conclusion that diamond+pants+shirt = Cool outfit? Commented Aug 24, 2011 at 21:26

2 Answers 2

1
if (data.data1 == "pants" && data.data2 == "shirt"){
    return { result: "Cool Outfit" };
}
Sign up to request clarification or add additional context in comments.

3 Comments

how would I chain this? for multiple options?
With that && just add more if statements
i meant if (data.data1 == "pants" && data.data2 == "shirt"){ return { result: "Cool Outfit" }; }else{ if (data.data1 == "pants" && data.data2 == "shirt"){ return { result: "Cool Outfit" }; } do I just keep on saying else?
1

That's going to depend on your logic to use. From the example posted, I can't derive the relationship from your input to your output. However, the general format will be like so:

 var myObj = yourJsonParser.ParseJson(someText);

 if(myObj.shapeId == "diamond")
    return { result: "Cool Outfit" };

You're returning a new object with data in a JSON-like format.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.