public void ParsingSpecialUnicodeCharacter() { var jsonObjectDict = new Dictionary <string, JsonValue>(); jsonObjectDict.Add("Test", JsonStringValue.FromString("/\b\f\n\r\t\"\\\ud834\uDD1E")); Assert.That(JsonObjectValue.FromDictionary(jsonObjectDict).ToString(), Is.EqualTo("{\"Test\":\"\\/\\b\\f\\n\\r\\t\\\"\\\\𝄞\"}")); }
public void SingleElementListJsonString() { ICollection <JsonValue> list = new Collection <JsonValue>(); list.Add(JsonStringValue.FromString("Test")); Assert.That(JsonArrayValue.FromList(list).ToString(), Is.EqualTo("[\"Test\"]")); }
public void AddOverridableAttributeWhichIsNotAvailable() { EventPayloadBuilder builder = new EventPayloadBuilder(new Dictionary <string, JsonValue>(), mockLogger); builder.AddOverridableAttribute("Overridable", JsonStringValue.FromString("Changed")); Assert.That(builder.Build(), Is.EqualTo("{\"Overridable\":\"Changed\"}")); }
public void MultipleElementObjectJsonString() { // given var jsonObjectDict = new Dictionary <string, JsonValue>(); jsonObjectDict.Add("Test", JsonBooleanValue.FromValue(false)); jsonObjectDict.Add("Test2", JsonStringValue.FromString("Value")); Assert.That(JsonObjectValue.FromDictionary(jsonObjectDict).ToString(), Is.EqualTo("{\"Test\":false,\"Test2\":\"Value\"}")); }
public void AddOverridableAttributeWhichIsAlreadyAvailable() { Dictionary <string, JsonValue> dict = new Dictionary <string, JsonValue>(); dict.Add("timestamp", JsonStringValue.FromString("Changed")); EventPayloadBuilder builder = new EventPayloadBuilder(dict, mockLogger); builder.AddOverridableAttribute("timestamp", JsonStringValue.FromString("ComingFromAgent")); Assert.That(builder.Build(), Is.EqualTo("{\"timestamp\":\"Changed\",\"dt.overridden_keys\":[\"timestamp\"]}")); }
public void RemovingReservedValuesAtInitializing() { Dictionary <string, JsonValue> dict = new Dictionary <string, JsonValue>(); dict.Add("dt", JsonStringValue.FromString("Removed")); dict.Add("dt.hello", JsonStringValue.FromString("Removed")); dict.Add("dt.type", JsonStringValue.FromString("Okay")); EventPayloadBuilder builder = new EventPayloadBuilder(dict, mockLogger); Assert.That(builder.Build(), Is.EqualTo("{\"dt.type\":\"Okay\"}")); }
public void AddNonOverridableAttributeWhichIsAlreadyAvailable() { Dictionary <string, JsonValue> dict = new Dictionary <string, JsonValue>(); dict.Add("dt.sid", JsonStringValue.FromString("MySession")); EventPayloadBuilder builder = new EventPayloadBuilder(dict, mockLogger); builder.AddNonOverridableAttribute("dt.sid", JsonStringValue.FromString("ComingFromAgent")); Assert.That(builder.Build(), Is.EqualTo("{\"dt.sid\":\"ComingFromAgent\"}")); }
public EventPayloadBuilder AddOverridableAttribute(string key, JsonValue value) { if (value != null) { if (attributes.ContainsKey(key)) { overriddenKeys.Add(JsonStringValue.FromString(key)); } else { attributes[key] = value; } } return(this); }
public void SendBizEventWithValidPayload() { // given var target = CreateSession().Build(); const string eventType = "SomeType"; Dictionary <string, JsonValue> attributes = new Dictionary <string, JsonValue>(); attributes.Add("value", JsonStringValue.FromString("Test")); // when target.SendBizEvent(eventType, attributes); // then mockLogger.Received(1).Debug($"{target} SendBizEvent({eventType},{attributes})"); mockBeacon.Received(1).SendBizEvent("SomeType", attributes); }
private void createProjectInformationFile() { // Create Project Information File JsonObjectCollection luamingJson = new JsonObjectCollection(); JsonStringValue projectNameJson = new JsonStringValue("PROJECT_NAME"); projectNameJson.Value = projectName; JsonStringValue packageNameJson = new JsonStringValue("PACKAGE_NAME"); packageNameJson.Value = packageName; JsonStringValue versionNameJson = new JsonStringValue("VERSION_NAME"); versionNameJson.Value = "1.0.0"; JsonNumericValue versionCodeJson = new JsonNumericValue("VERSION_CODE"); versionCodeJson.Value = 1; JsonStringValue offlineIconJson = new JsonStringValue("OFFLINE_ICON"); offlineIconJson.Value = "icon.png"; JsonStringValue mainScriptJson = new JsonStringValue("MAIN_SCRIPT"); mainScriptJson.Value = "main.lua"; JsonStringValue orientationJson = new JsonStringValue("ORIENTATION"); if (isLandscape == true) { orientationJson.Value = "landscape"; } else { orientationJson.Value = "portrait"; } luamingJson.Add(projectNameJson); luamingJson.Add(packageNameJson); luamingJson.Add(versionNameJson); luamingJson.Add(versionCodeJson); luamingJson.Add(offlineIconJson); luamingJson.Add(mainScriptJson); luamingJson.Add(orientationJson); StreamWriter sw = File.CreateText(dstPath + @"\assets\LuamingProject.json"); sw.Write(luamingJson.ToString()); sw.Close(); }
private void createProjectInformationFile() { // Create Project Information File JsonObjectCollection luamingJson = new JsonObjectCollection(); JsonStringValue projectNameJson = new JsonStringValue("PROJECT_NAME"); projectNameJson.Value = project_name_textbox.Text.ToString(); JsonStringValue packageNameJson = new JsonStringValue("PACKAGE_NAME"); packageNameJson.Value = package_name_textbox.Text.ToString(); JsonStringValue versionNameJson = new JsonStringValue("VERSION_NAME"); versionNameJson.Value = version_name_textbox.Text.ToString(); JsonNumericValue versionCodeJson = new JsonNumericValue("VERSION_CODE"); versionCodeJson.Value = Int32.Parse(version_code_textbox.Text.ToString()); JsonStringValue offlineIconJson = new JsonStringValue("OFFLINE_ICON"); offlineIconJson.Value = offline_icon_textbox.Text.ToString(); JsonStringValue mainScriptJson = new JsonStringValue("MAIN_SCRIPT"); mainScriptJson.Value = main_script_textbox.Text.ToString(); JsonStringValue orientationJson = new JsonStringValue("ORIENTATION"); if (radioLandscape.IsChecked == true) { orientationJson.Value = "landscape"; } else { orientationJson.Value = "portrait"; } luamingJson.Add(projectNameJson); luamingJson.Add(packageNameJson); luamingJson.Add(versionNameJson); luamingJson.Add(versionCodeJson); luamingJson.Add(offlineIconJson); luamingJson.Add(mainScriptJson); luamingJson.Add(orientationJson); StreamWriter sw = File.CreateText(MainWindow.projectPath + @"\assets\LuamingProject.json"); sw.Write(luamingJson.ToString()); sw.Close(); }
/// <summary> /// Helper method for converting a simple JSON token to a JSON value. /// </summary> /// <param name="token">the token to convert to a JSON value</param> /// <returns>the converted JSON value</returns> private static JsonValue TokenToSimpleJsonValue(JsonToken token) { switch (token.TokenType) { case JsonTokenType.LITERAL_NULL: return(JsonNullValue.Null); case JsonTokenType.LITERAL_BOOLEAN: return(JsonBooleanValue.FromLiteral(token.Value)); case JsonTokenType.VALUE_STRING: return(JsonStringValue.FromString(token.Value)); case JsonTokenType.VALUE_NUMBER: return(JsonNumberValue.FromNumberLiteral(token.Value)); default: throw new JsonParserException($"Internal parser error: Unexpected JSON token \"{token}\""); } }
public void EmptyValueJsonString() { Assert.That(JsonStringValue.FromString("").ToString(), Is.EqualTo("\"\"")); }
public void ValueReturnsValueOfFromStringMethod() { Assert.That(JsonStringValue.FromString("").Value, Is.EqualTo("")); Assert.That(JsonStringValue.FromString("a").Value, Is.EqualTo("a")); Assert.That(JsonStringValue.FromString("foobar").Value, Is.EqualTo("foobar")); }
public void FromStringReturnsNullIfArgumentIsNull() { Assert.That(JsonStringValue.FromString(null), Is.Null); }
public void IsStringType() { Assert.That(JsonStringValue.FromString("").ValueType, Is.EqualTo(JsonValueType.STRING)); }
public static void handleRequest(HttpProcessor p, StreamReader inputData, string method) { //paymentServer_dataBase DBHandler = new paymentServer_dataBase(); JsonObjectCollection headers; JsonObjectCollection messageType; JsonObjectCollection user; JsonObjectCollection merchant; JsonObjectCollection customer; JsonObjectCollection transactions; //Define outgoing JSON message structures JsonStringValue Accept_Encoding = new JsonStringValue("Accept-Encoding", "gzip,deflate,sdch"); JsonStringValue Cookie = new JsonStringValue("Cookie", "_gauges_unique_month=1; _gauges_unique_year=1; _gauges_unique=1"); JsonStringValue Accept_Language = new JsonStringValue("Accept-Language", "en-CA,en-GB,en-US;q=0.8,en;q=0.6"); JsonStringValue Accept = new JsonStringValue("Accept", "application/json, text/json"); JsonStringValue Host = new JsonStringValue("Host", "paymentserver.dynu.com"); JsonStringValue Referer = new JsonStringValue("Referer", "https://paymentserver.dynu.com"); JsonStringValue Connection = new JsonStringValue("Connection", "close"); JsonStringValue User_Agent = new JsonStringValue("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.69 Safari/537.36"); headers = new JsonObjectCollection(); headers.Name = "headers"; headers.Add(Accept_Encoding); headers.Add(Cookie); headers.Add(Accept_Language); headers.Add(Accept); headers.Add(Host); headers.Add(Referer); headers.Add(Connection); headers.Add(User_Agent); JsonNumericValue code = new JsonNumericValue("code", -1); JsonBooleanValue request = new JsonBooleanValue("request", false); JsonBooleanValue response = new JsonBooleanValue("response", false); JsonStringValue details = new JsonStringValue("details", ""); messageType = new JsonObjectCollection(); messageType.Name = "messageType"; messageType.Add(code); messageType.Add(request); messageType.Add(response); messageType.Add(details); JsonStringValue bankCode = new JsonStringValue("bankCode", ""); JsonStringValue accountNum = new JsonStringValue("accountNum", ""); JsonStringValue accountPWD = new JsonStringValue("accountPWD", ""); JsonNumericValue acctBalance = new JsonNumericValue("acctBalance", -1); JsonObjectCollection account = new JsonObjectCollection(); account.Name = "account"; account.Add(bankCode); account.Add(accountNum); account.Add(accountPWD); account.Add(acctBalance); JsonNumericValue POSHWID = new JsonNumericValue("POSHWID", -1); JsonStringValue currentDK = new JsonStringValue("currentDK", ""); JsonStringValue nextDK = new JsonStringValue("nextDK", ""); JsonObjectCollection hardwareInfo = new JsonObjectCollection(); hardwareInfo.Name = "hardwareInfo"; hardwareInfo.Add(POSHWID); hardwareInfo.Add(currentDK); hardwareInfo.Add(nextDK); JsonNumericValue DOBDay = new JsonNumericValue("DOBDay", -1); JsonNumericValue DOBMonth = new JsonNumericValue("DOBMonth", -1); JsonNumericValue DOBYear = new JsonNumericValue("DOBYear", -1); JsonObjectCollection dateOfBirth = new JsonObjectCollection(); dateOfBirth.Name = "dateOfBirth"; dateOfBirth.Add(DOBDay); dateOfBirth.Add(DOBMonth); dateOfBirth.Add(DOBYear); JsonStringValue firstName = new JsonStringValue("firstName", ""); JsonStringValue middleName = new JsonStringValue("middleName", ""); JsonStringValue lastName = new JsonStringValue("lastName", ""); JsonStringValue occupation = new JsonStringValue("occupation", ""); JsonNumericValue SIN = new JsonNumericValue("SIN", -1); JsonStringValue address1 = new JsonStringValue("address1", ""); JsonStringValue address2 = new JsonStringValue("address2", ""); JsonStringValue city = new JsonStringValue("city", ""); JsonStringValue province = new JsonStringValue("province", ""); JsonStringValue country = new JsonStringValue("country", ""); JsonStringValue postalCode = new JsonStringValue("postalCode", ""); JsonStringValue email = new JsonStringValue("email", ""); JsonNumericValue phoneNumber = new JsonNumericValue("phoneNumber", -1); JsonObjectCollection personalInfo = new JsonObjectCollection(); personalInfo.Name = "personalInfo"; personalInfo.Add(firstName); personalInfo.Add(middleName); personalInfo.Add(lastName); personalInfo.Add(email); personalInfo.Add(dateOfBirth); personalInfo.Add(occupation); personalInfo.Add(SIN); personalInfo.Add(address1); personalInfo.Add(address2); personalInfo.Add(city); personalInfo.Add(province); personalInfo.Add(country); personalInfo.Add(postalCode); personalInfo.Add(phoneNumber); JsonStringValue username = new JsonStringValue("username", ""); JsonStringValue password = new JsonStringValue("password", ""); JsonObjectCollection userID = new JsonObjectCollection(); userID.Name = "userID"; userID.Add(username); userID.Add(password); JsonBooleanValue receiveCommunication = new JsonBooleanValue("receiveCommunication", false); JsonStringValue userType = new JsonStringValue("userType", ""); JsonNumericValue userNo = new JsonNumericValue("userNo", -1); JsonStringValue transactionHistory = new JsonStringValue("transactionHistory", ""); user = new JsonObjectCollection(); user.Name = "user"; user.Add(userNo); user.Add(userType); user.Add(transactionHistory); user.Add(receiveCommunication); user.Add(account); user.Add(hardwareInfo); user.Add(userID); user.Add(personalInfo); JsonNumericValue merchantID = new JsonNumericValue("merchantID", -1); JsonStringValue merchantName = new JsonStringValue("merchantName", ""); merchant = new JsonObjectCollection(); merchant.Name = "merchant"; merchant.Add(merchantID); merchant.Add(merchantName); JsonStringValue custUsername = new JsonStringValue("custUsername", ""); JsonStringValue custPWD = new JsonStringValue("custPWD", ""); customer = new JsonObjectCollection(); customer.Name = "customer"; customer.Add(custUsername); customer.Add(custPWD); JsonNumericValue year = new JsonNumericValue("year", -1); JsonNumericValue month = new JsonNumericValue("month", -1); JsonNumericValue day = new JsonNumericValue("day", -1); JsonObjectCollection transactionDate = new JsonObjectCollection(); transactionDate.Name = "transactionDate"; transactionDate.Add(year); transactionDate.Add(month); transactionDate.Add(day); JsonNumericValue hour = new JsonNumericValue("hour", -1); JsonNumericValue minute = new JsonNumericValue("minute", -1); JsonNumericValue second = new JsonNumericValue("second", -1); JsonObjectCollection transactionTime = new JsonObjectCollection(); transactionTime.Name = "transactionTime"; transactionTime.Add(hour); transactionTime.Add(minute); transactionTime.Add(second); JsonStringValue merchantUsername = new JsonStringValue("merchantUsername", ""); JsonStringValue merchantPWD = new JsonStringValue("merchantPWD", ""); JsonObjectCollection merchantIdent = new JsonObjectCollection(); merchantIdent.Name = "merchantIdent"; merchantIdent.Add(merchantUsername); merchantIdent.Add(merchantPWD); JsonNumericValue transactionID = new JsonNumericValue("transactionID", -1); JsonNumericValue debitAmount = new JsonNumericValue("debitAmount", -1); JsonNumericValue creditAmount = new JsonNumericValue("creditAmount", -1); JsonNumericValue balance = new JsonNumericValue("balance", -1); JsonNumericValue receiptNo = new JsonNumericValue("receiptNo", -1); transactions = new JsonObjectCollection(); transactions.Name = "transactions"; transactions.Add(transactionID); transactions.Add(debitAmount); transactions.Add(creditAmount); transactions.Add(balance); transactions.Add(receiptNo); transactions.Add(transactionDate); transactions.Add(transactionTime); transactions.Add(merchantID); //create JSON object JsonObjectCollection defineResponse = new JsonObjectCollection(); if (method == "GET") { Console.WriteLine("GET request: {0}", p.http_url); //build response content from already defined JSON Objects defineResponse.Insert(0, headers); defineResponse.Add(messageType); defineResponse.Add(user); defineResponse.Add(merchantIdent); defineResponse.Add(customer); defineResponse.Add(transactions); } /* * Handle 'POST' message. Requests form the mobile application are handled here */ if (method == "POST") {/* * Console.WriteLine("POST request: {0}", p.http_url); * * //parse the input data * string data = inputData.ReadToEnd(); * JObject received = JObject.Parse(data); * JObject msgType = (JObject)received.SelectToken("messageType"); * int transactionCode = (int)msgType.SelectToken("code"); * Console.WriteLine("Transaction code: {0}", transactionCode); * * //Determine anad handle the received transaction code * switch (transactionCode) * { * /* * handle user authentication request */ /*case ((int)clientIncomingCodeEnum.IN_CODE_LOGIN_REQ): * JObject cust = (JObject)received.SelectToken("customer"); * string authString = ""; * string uName = (string)cust.SelectToken("custUsername"); * string PWD = (string)cust.SelectToken("custPWD"); * authString += uName; * authString += PWD; * Console.WriteLine("custUsename: {0}", uName); * Console.WriteLine("custPWD: {0}", PWD); * * //Call the ServerWorker function * if (paymentServer_requestWorker.authenticateUser(DBHandler, authString)) * { * messageType = insert(messageType, code, new JsonNumericValue("code", (int)clientOutgoingCodeEnum.OUT_CODE_LOGIN_SUCCESS)); * messageType = insert(messageType, response, new JsonBooleanValue("response", true)); * messageType = insert(messageType, request, new JsonBooleanValue("request", false)); * messageType = insert(messageType, details, new JsonStringValue("details", "Authentication Successful")); * } * else * { * messageType = insert(messageType, code, new JsonNumericValue("code", (int)clientOutgoingCodeEnum.OUT_CODE_LOGIN_FAILURE)); * messageType = insert(messageType, response, new JsonBooleanValue("response", true)); * messageType = insert(messageType, request, new JsonBooleanValue("request", false)); * messageType = insert(messageType, details, new JsonStringValue("details", "Invalid username and passowrd combination")); * } * //build response message content from already defined JSON Objects * defineResponse.Insert(0, headers); * defineResponse.Add(messageType); * break; * * /* * handle new user sign-up request */ /* case ((int)clientIncomingCodeEnum.IN_CODE_SIGN_UP_REQ): * UserProfile newProfile = new UserProfile(); * * //Retrieve encapsulated JSON objects from message * JObject newUser = (JObject)received.SelectToken("user"); * JObject acct = (JObject)newUser.SelectToken("account"); * JObject UID = (JObject)newUser.SelectToken("userID"); * JObject persInfo = (JObject)newUser.SelectToken("personalInfo"); * JObject DOB = (JObject)persInfo.SelectToken("dateOfBirth"); * JObject HWInfo = (JObject)newUser.SelectToken("hardwareInfo"); * * * //Populate the newProfile object with the information received from the client * newProfile.userType = (string)newUser.SelectToken("userType"); * newProfile.receiveCommunication = Convert.ToInt16((bool)newUser.SelectToken("receiveCommunication")); * newProfile.bankCode = (string)acct.SelectToken("bankCode"); * newProfile.accountNum = (string)acct.SelectToken("accountNum"); * newProfile.accountPWD = (string)acct.SelectToken("accountPWD"); * newProfile.username = (string)UID.SelectToken("username"); * newProfile.password = (string)UID.SelectToken("password"); * newProfile.firstName = (string)persInfo.SelectToken("firstName"); * newProfile.middleName = (string)persInfo.SelectToken("middleName"); * newProfile.lastName = (string)persInfo.SelectToken("lastName"); * newProfile.DOBDay = (int)DOB.SelectToken("DOBDay"); * newProfile.DOBMonth = (int)DOB.SelectToken("DOBMonth"); * newProfile.DOBYear = (int)DOB.SelectToken("DOBYear"); * newProfile.occupation = (string)persInfo.SelectToken("occupation"); * newProfile.SIN = (int)persInfo.SelectToken("SIN"); * newProfile.address1 = (string)persInfo.SelectToken("address1"); * newProfile.address2 = (string)persInfo.SelectToken("address2"); * newProfile.city = (string)persInfo.SelectToken("city"); * newProfile.province = (string)persInfo.SelectToken("province"); * newProfile.country = (string)persInfo.SelectToken("country"); * newProfile.postalCode = (string)persInfo.SelectToken("postalCode"); * newProfile.email = (string)persInfo.SelectToken("email"); * newProfile.phoneNumber = (int)persInfo.SelectToken("phoneNumber"); * newProfile.POSHWID = (int)HWInfo.SelectToken("POSHWID"); * newProfile.authenticationString = ""; * newProfile.authenticationString += newProfile.username; * newProfile.authenticationString += newProfile.password; * * //pass the populated newProfile information to ServerWorker to try and create a new profile * //and build response message to client based on the return code receiveed from ServerWorker * if (paymentServer_requestWorker.createNewProfile(DBHandler, newProfile) == ResultCodeType.RESULT_CREATE_PROFILE_SUCCESS) * { * messageType = insert(messageType, code, new JsonNumericValue("code", (int)clientOutgoingCodeEnum.OUT_CODE_SIGN_UP_SUCCESS)); * messageType = insert(messageType, response, new JsonBooleanValue("response", true)); * messageType = insert(messageType, request, new JsonBooleanValue("request", false)); * messageType = insert(messageType, details, new JsonStringValue("details", "User account created")); * } * else * { * messageType = insert(messageType, code, new JsonNumericValue("code", (int)clientOutgoingCodeEnum.OUT_CODE_SIGN_UP_FAILURE)); * messageType = insert(messageType, response, new JsonBooleanValue("response", true)); * messageType = insert(messageType, request, new JsonBooleanValue("request", false)); * messageType = insert(messageType, details, new JsonStringValue("details", "Could not create profile. The email provided is already registered")); * } * * //build response message content from already defined JSON Objects * defineResponse.Insert(0, headers); * defineResponse.Add(messageType); * break; * * /* * handle get user profile request */ /*case ((int)clientIncomingCodeEnum.IN_CODE_GET_USER_PROFILE): * //Retrieve encapsulated JSON objects from message * JObject requester = (JObject)received.SelectToken("user"); * int userNum = (int)requester.SelectToken("userNo"); * * GetProfileResultType UserProf = paymentServer_requestWorker.getUserProfile(DBHandler, userNum); * if (UserProf.status == ResultCodeType.UPDATE_USER_PROFILE_SUCCESS) * { * //populate messageType fields * messageType = insert(messageType, code, new JsonNumericValue("code", (int)clientOutgoingCodeEnum.OUT_CODE_SEND_USER_PROFILE_SUCCESS)); * messageType = insert(messageType, response, new JsonBooleanValue("response", true)); * messageType = insert(messageType, request, new JsonBooleanValue("request", false)); * * //populate User fields * user = insert(user, userNo, new JsonNumericValue("userNo", (int)UserProf.profile.userNo)); * user = insert(user, userType, new JsonStringValue("userType", (string)UserProf.profile.userType)); * user = insert(user, transactionHistory, new JsonStringValue("transactionHistory", (string)UserProf.profile.transactionHistory)); * user = insert(user, receiveCommunication, new JsonBooleanValue("receiveCommunication", Convert.ToBoolean(UserProf.profile.receiveCommunication))); * * account = insert(account, bankCode, new JsonStringValue("bankCode", (string)UserProf.profile.bankCode)); * account = insert(account, accountNum, new JsonStringValue("accountNum", (string)UserProf.profile.accountNum)); * account = insert(account, accountPWD, new JsonStringValue("accountPWD", (string)UserProf.profile.accountPWD)); * account = insert(account, acctBalance, new JsonNumericValue("acctBalance", (int)UserProf.profile.acctBalance)); * user = insert(user, account, account); * * hardwareInfo = insert(hardwareInfo, POSHWID, new JsonNumericValue("POSHWID", (int)UserProf.profile.POSHWID)); * hardwareInfo = insert(hardwareInfo, currentDK, new JsonStringValue("currentDK", (string)UserProf.profile.currentDK)); * hardwareInfo = insert(hardwareInfo, nextDK, new JsonStringValue("nextDK", (string)UserProf.profile.nextDK)); * user = insert(user, hardwareInfo, hardwareInfo); * * userID = insert(userID, username, new JsonStringValue("username", (string)UserProf.profile.username)); * userID = insert(userID, password, new JsonStringValue("password", (string)UserProf.profile.password)); * user = insert(user, userID, userID); * * personalInfo = insert(personalInfo, firstName, new JsonStringValue("firstName", (string)UserProf.profile.firstName)); * personalInfo = insert(personalInfo, lastName, new JsonStringValue("lastName", (string)UserProf.profile.lastName)); * personalInfo = insert(personalInfo, middleName, new JsonStringValue("middleName", (string)UserProf.profile.middleName)); * personalInfo = insert(personalInfo, email, new JsonStringValue("email", (string)UserProf.profile.email)); * personalInfo = insert(personalInfo, occupation, new JsonStringValue("occupation", (string)UserProf.profile.occupation)); * personalInfo = insert(personalInfo, SIN, new JsonNumericValue("SIN", (int)UserProf.profile.SIN)); * personalInfo = insert(personalInfo, address1, new JsonStringValue("address1", (string)UserProf.profile.address1)); * personalInfo = insert(personalInfo, address2, new JsonStringValue("address2", (string)UserProf.profile.address2)); * personalInfo = insert(personalInfo, city, new JsonStringValue("email", (string)UserProf.profile.city)); * personalInfo = insert(personalInfo, province, new JsonStringValue("province", (string)UserProf.profile.province)); * personalInfo = insert(personalInfo, country, new JsonStringValue("country", (string)UserProf.profile.country)); * personalInfo = insert(personalInfo, postalCode, new JsonStringValue("postalCode", (string)UserProf.profile.postalCode)); * personalInfo = insert(personalInfo, phoneNumber, new JsonNumericValue("phoneNumber", (int)UserProf.profile.phoneNumber)); * dateOfBirth = insert(dateOfBirth, DOBDay, new JsonNumericValue("DOBDay", (int)UserProf.profile.DOBDay)); * dateOfBirth = insert(dateOfBirth, DOBMonth, new JsonNumericValue("DOBMonthr", (int)UserProf.profile.DOBMonth)); * dateOfBirth = insert(dateOfBirth, DOBYear, new JsonNumericValue("DOBYear", (int)UserProf.profile.DOBYear)); * personalInfo = insert(personalInfo, dateOfBirth, dateOfBirth); * user = insert(user, personalInfo, personalInfo); * } * else * { * messageType = insert(messageType, code, new JsonNumericValue("code", (int)clientOutgoingCodeEnum.OUT_CODE_SEND_USER_PROFILE_FAILURE)); * messageType = insert(messageType, response, new JsonBooleanValue("response", true)); * messageType = insert(messageType, request, new JsonBooleanValue("request", false)); * messageType = insert(messageType, details, new JsonStringValue("details", "Server error - Could not get profile data")); * } * //build response message content from already defined JSON Objects * defineResponse.Insert(0, headers); * defineResponse.Add(messageType); * defineResponse.Add(user); * break; * * case ((int)clientIncomingCodeEnum.IN_CODE_PROCESS_PAYMENT_REQ): * break; * }*/ } //finalize outgoing JSON message JsonObjectCollection completeResponse = new JsonObjectCollection(); JsonObjectCollection packagedResponse = new JsonObjectCollection(); completeResponse.Add(defineResponse); //Write message to client Console.WriteLine("Response to Client: \n{0}", completeResponse.ToString()); byte[] message = JsonStringToByteArray(completeResponse.ToString()); p.sslStream.Write(message); }
private void button1_Click(object sender, EventArgs e) { FileIO.JsonOutput("AA", Scene.GetChildList()); return; // const string jsonText = // "{" + // " \"FirstValue\": 1.1," + // " \"SecondValue\": \"some text\"," + // " \"TrueValue\": true" + // "}"; // // 1. parse sample // richTextBox1.AppendText("\n"); // richTextBox1.AppendText("Source data:\n"); // richTextBox1.AppendText(jsonText); // richTextBox1.AppendText("\n"); // // JsonTextParser parser = new JsonTextParser(); // JsonObject obj = parser.Parse(jsonText); // // richTextBox1.AppendText("\n"); // richTextBox1.AppendText("Parsed data with indentation in JSON data format:\n"); // richTextBox1.AppendText(obj.ToString()); // richTextBox1.AppendText("\n"); // // JsonUtility.GenerateIndentedJsonText = false; // // richTextBox1.AppendText("\n"); // richTextBox1.AppendText("Parsed data without indentation in JSON data format:\n"); // richTextBox1.AppendText(obj.ToString()); // richTextBox1.AppendText("\n"); // // // enumerate values in json object // richTextBox1.AppendText("\n"); // richTextBox1.AppendText("Parsed object contains these nested fields:\n"); // foreach (JsonObject field in obj as JsonObjectCollection) // { // string name = field.Name; // string value = string.Empty; // string type = field.GetValue().GetType().Name; // // // try to get value. // switch (type) // { // case "String": // value = (string)field.GetValue(); // break; // case "Double": // value = field.GetValue().ToString(); // break; // case "Boolean": // value = field.GetValue().ToString(); // break; // default: // // in this sample we'll not parse nested arrays or objects. // throw new NotSupportedException(); // } // richTextBox1.AppendText(String.Format("{0} {1} {2}", // name.PadLeft(15), type.PadLeft(10), value.PadLeft(15))); // } // richTextBox1.AppendText("\n"); // // // 2. generate sample // richTextBox1.AppendText("\n"); // root object JsonObjectCollection collection = new JsonObjectCollection(); // nested values //new JsonArrayCollection() JsonArrayCollection aa = new JsonArrayCollection("TEST"); aa.Add(new JsonStringValue(null, "a")); aa.Add(new JsonStringValue(null, "b")); aa.Add(new JsonStringValue(null, "c")); JsonStringValue[] temp = new JsonStringValue[3]; temp[0] = new JsonStringValue("Array", "A"); temp[1] = new JsonStringValue("Array", "B"); temp[2] = new JsonStringValue("Array", "C"); JsonStringValue[] temp2 = new JsonStringValue[3]; temp2[0] = new JsonStringValue("Object", "1"); temp2[1] = new JsonStringValue("Object", "2"); temp2[2] = new JsonStringValue("Object", "3"); collection.Add((aa)); collection.Add(new JsonArrayCollection(temp)); collection.Add(new JsonObjectCollection(temp2)); collection.Add(new JsonStringValue("FirstName", "Pavel")); collection.Add(new JsonStringValue("LastName", "Lazureykis")); collection.Add(new JsonNumericValue("Age", 23)); collection.Add(new JsonStringValue("Email", "*****@*****.**")); collection.Add(new JsonBooleanValue("HideEmail", true)); richTextBox1.AppendText("Generated object:\n"); JsonUtility.GenerateIndentedJsonText = true; richTextBox1.AppendText(collection.ToString()); richTextBox1.AppendText("\n"); // 3. generate own library for working with own custom json objects /// /// Note that generator in this pre-release version of library supports /// only JsonObjectCollection in root level ({...}) and only simple /// value types can be nested. Not arrays or other objects. /// Also names of nested values cannot contain spaces or starts with /// numeric symbols. They must comply with C# variable declaration rules. /// // JsonGenerator generator = new JsonGenerator(); // generator.GenerateLibrary("Person", collection, @"C:\"); richTextBox1.AppendText("\n"); System.IO.File.WriteAllText("test.json", collection.ToString()); }
public void AnyValueJsonString() { Assert.That(JsonStringValue.FromString("Test").ToString(), Is.EqualTo("\"Test\"")); }