Ir para o conteúdo

Funções JSON

Introdução

Notação de Objeto JavaScript As funções (JSON) permitem a manipulação de dados no formato JSON. Para obter mais informações sobre JSON, consulte IETF RFC 8259: The JavaScript Object Notation (JSON) Data Interchange Format.

GetJSONString

Declaração

string GetJSONString(string json_string, string path)

Sintaxe

GetJSONString(<json_string>, <path>)

Parâmetros Obrigatórios

  • json_string: Uma string de objeto JSON para analisar dados.
  • path: Um caminho que representa a localização dos dados na string do objeto JSON.

Descrição

Recupera dados de uma string de objeto JSON usando o caminho fornecido.

Importante

Esta função requer o Design Studio versão 11.28 ou posterior e o agente versão 11.28 ou posterior.

Exemplos

// Define the JSON object string:
json_string = '{ "company": [{ "nome": "Jitterbit", "produto": [{ "tipo": "iPaaS", "nome": "Harmony iPaaS" },{ "tipo": "EDI", "nome": "Harmony EDI " }] }] }';

GetJSONString(json_string, "/company/[0]/product/[1]/name");
// Returns "Harmony EDI"

GetJSONString(json_string, "/company/[0]/product");
// Returns '[{"type":"iPaaS","name":"Harmony iPaaS"},{"type":"EDI","name":"Harmony EDI"}]'

JSONParser

Declaração

dictionary JSONParser(string json_string)

Sintaxe

JSONParser(<json_string>)

Parâmetros Obrigatórios

  • json_string: Uma string de objeto JSON para converter em um objeto JSON.

Descrição

Converte uma string de objeto JSON em um objeto JSON.

Importante

Esta função requer o Design Studio versão 11.29 ou posterior e o agente versão 11.29 ou posterior.

Exemplos

// Define the JSON object string:
json_string = '{ "company": [{ "nome": "Jitterbit", "produto": [{ "tipo": "iPaaS", "nome": "Harmony iPaaS" },{ "tipo": "EDI", "nome": "Harmony EDI " }] }] }';

// Convert the JSON object string into a JSON object:
json_object = JSONParser(json_string);

result = json_object["company"][0]["product"][1]["name"];
// Equals "Harmony EDI"

result = json_object["company"][0]["product"];
// Equals {"[name=>""Harmony iPaaS"",type=>""iPaaS""]","[name=>""Harmony EDI"",type=>""EDI""]"}

JSONStringify

Declaração

string JSONStringify(dictionary json_object)

Sintaxe

JSONStringify(<json_object>)

Parâmetros Obrigatórios

  • json_object: Um objeto JSON para converter em uma string de objeto JSON.

Descrição

Converte um objeto JSON em uma string de objeto JSON.

Importante

Esta função requer o Design Studio versão 11.30 ou posterior e o agente versão 11.30 ou posterior.

Exemplo

// Define the JSON object structure:
json_object = Dict();
json_object["company"][0] = Dict();
json_object["company"][0]["name"] = "Jitterbit";
json_object["company"][0]["product"][0] = Dict();
json_object["company"][0]["product"][0]["type"] = "iPaaS";
json_object["company"][0]["product"][0]["name"] = "Harmony iPaaS";
json_object["company"][0]["product"][1] = Dict();
json_object["company"][0]["product"][1]["type"] = "EDI";
json_object["company"][0]["product"][1]["name"] = "Harmony EDI";

JSONStringify(json_object);
// Returns '{"company":[{"name":"Jitterbit", "product":[{"name":"Harmony iPaaS", "type":"iPaaS"}, {"name":"Harmony EDI", "type":"EDI"}]}]}'