2

Currently having an issue creating a reusable object that I will need to use in a JSON construct string function.

Currently I have the following to create the bulk of the JSON string:

var data = new
  {
    record = new
      {
        value1 = Row.value1,
        value2 = Row.value2,
        form_values = new Dictionary<string, string>()
       }
   };
data.record.form_values["833b"] = Row.value3.ToString();
data.record.form_values["98wq"] = BuildMultiSelectList(Row.value3.ToString()); 



public object BuildMultiSelectList(string datavalue)
{
    var choicelist = new { 
                      choice_values: [datavalue],
                      other_values: [],
                      };
    return choicelist;
}

The top half all works fine, though the function BuildMultiSelectList is giving errors such as "choice_values" does not exist in the current context and datavalue does not exist in the current context.

Any insight on why this has gone a bit rouge will be appreciated.

1
  • 1
    choice_values: [datavalue], other_values: [], isn't valid C#. Use the conventional anonymous type syntax as you did in the first code block. Commented May 16, 2016 at 0:18

1 Answer 1

1

May be you are just mixing colon : with =?

        var choicelist = new { 
                      choice_values = new string[] {datavalue},
                      other_values = new[] {},
                      };
Sign up to request clarification or add additional context in comments.

1 Comment

I have been known to be a bit simple sometimes... Embarrassing miss I think its bed time!

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.