I have the following JSON:
{"test1":"1", "test2": {"test21":"21", "test22":"22"}}"
but I'm having troubles parsing it. Actually, I'm somehow trying to read "test21" but don't know how to reach it. I tried this but it's not good:
UnicodeString myJSON = "{\"test1\" :\"1\",\"test2\":{\"test21\":\"21\",\"test22\":\"22\"}}";
TJSONObject *JSON = (TJSONObject*)TJSONObject::ParseJSONValue(myJSON);
TJSONValue *test2 = (TJSONValue*)JSON->Get("test2");
//TJSONString* test21 = (TJSONString*)test2->Get("test21");
TJSONObject *JSON = (TJSONObject*)TJSONObject::ParseJSONValue(myJSON);
TJSONPair *pair = JSON->Get("test2");
TJSONObject *jsonObj = (TJSONObject*) pair->JsonValue;
TJSONPair *test21 = jsonObj->Get("test21");
String value = test21->JsonValue->ToString();
Related
Is there a way to clear the local passwords store and add a new password-form to it at runtime?
To be more explicit, its ideal if I can accomplish this from the newtab WebUI component that I'm working on, specifically from the instant_service messages handler that I've added to it in order to process various UI aspects of the NTP page.
Let's assume I have the following code:
autofill::FormData CreateNewLoginFormData(std::string url, std::string actionUrl, std::string formIdOrName,
std::string userField, std::string username,
std::string pwdField, std::string password) {
autofill::FormData form_data;
form_data.url = GURL(url);
form_data.action = GURL(actionUrl);
form_data.name = formIdOrName;
autofill::FormFieldData field;
field.name = userField;
field.id_attribute = field.name;
field.name_attribute = field.name;
field.value = username;
field.form_control_type = "text";
field.unique_id = field.id_attribute;
form_data.fields.push_back(field);
field.name = pwdField;
field.id_attribute = field.name;
field.name_attribute = field.name;
field.value = password;
field.form_control_type = "password";
field.unique_id = field.id_attribute;
form_data.fields.push_back(field);
return form_data;
}
How to add this new FormData to the PasswordStore inside chromium?
Found an answer myself.
The idea is to instantiate the password store for the current profile:
password_manager::PasswordStore* password_store =
static_cast<password_manager::PasswordStore*>(
PasswordStoreFactory::GetForProfile(
profile_, ServiceAccessType::IMPLICIT_ACCESS)
.get());
And later in code add a stored password like this:
password_manager::PasswordForm signin_form;
signin_form.signon_realm = GURL(theLink).spec();
signin_form.password_value = base::UTF8ToUTF16(thePassword);
signin_form.username_value = base::UTF8ToUTF16(theUsername);
signin_form.url = GURL(theLink);
signin_form.skip_zero_click = true;
password_store_->AddLogin(signin_form);
I'm trying to get ID3D11VideoDecoder Decoder with h264 decoder profile but catching exception on Windows Phone 8.
Using this code:
DX::ThrowIfFailed(device.Get()->QueryInterface(__uuidof(ID3D11VideoDevice), (void**)&videoDevice));
GUID guid = {0x1b81be68, 0xa0c7,0x11d3,{0xb9,0x84,0x00,0xc0,0x4f,0x2e,0x73,0xc5}};
D3D11_VIDEO_DECODER_DESC *desc = new D3D11_VIDEO_DECODER_DESC();
desc->Guid = guid;
desc->OutputFormat = DXGI_FORMAT_420_OPAQUE;
desc->SampleHeight = 480;
desc->SampleWidth = 800;
D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
ID3D11VideoDecoder *decoder;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));
PS. I tried SharpDX for this and got the same issue.
It seems you didn't pass in a valid D3D11_VIDEO_DECODER_CONFIG variable. you just define a pointer of struct D3D11_VIDEO_DECODER_CONFIG and didn't set the values of it before calling function CreateVideoDecoder.
D3D11_VIDEO_DECODER_CONFIG *conf = new D3D11_VIDEO_DECODER_CONFIG();
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));
You can try it as below.
D3D11_VIDEO_DECODER_CONFIG conf
ZeroMemory(&conf, sizeof(conf));
conf.guidConfigBitstreamEncryption = xxx;
...
conf.ConfigDecoderSpecific = xxx;
DX::ThrowIfFailed(videoDevice.Get()->CreateVideoDecoder(desc, conf, &decoder));
So, I found solution.
for H264 decoder ConfigBitstreamRaw field must be "2". Not "1", not "0". Only "2". Like this
VideoDecoderDescription decoderDescription = new VideoDecoderDescription();
decoderDescription.OutputFormat = Format.Opaque420;
decoderDescription.SampleHeight = 480;
decoderDescription.SampleWidth = 800;
decoderDescription.Guid = _formatGuid;
VideoDecoderConfig config = new VideoDecoderConfig();
config.ConfigMinRenderTargetBuffCount = 1;
config.ConfigBitstreamRaw = 2;
Ok! I have a flashVar variable that is coming into Flash, its URL encoded but I have already decoded it. My problem is I want the set of variables to be pushed into an array.
Let's say the variables are
"&text0=Enter Text...&size0=18&font0=Arial&color0=0&rotation0=0&y0=360&x0=640&text1=Enter
Text...&size1=18&font1=Arial&color1=0&rotation1=0&y1=360&x1=640"
and so on...
What I want is the variables to go into an array like
myArray[0].text = Enter Text...
myArray[0].size = 18]
myArray[0].font = Arial
myArray[0].color = 0
myArray[0].rotation = 0
myArray[0].y = 360
myArray[0].x = 640
myArray[1].text = ...........
.............................
.............................
myArray[n].text = ...........
I think there must be some way to do this. Most probably I'm thinking regular expression, but I'm pretty bad at regular expression. Please some help would be very very appreciated.
Thank You!
You don't have to decode your query string, just use the URLVariables object - it will do all the decoding for you. Then iterate over its dynamic properties to create your array. Use a RegExp to find the index numbers at the end of your variable keys:
function parseURLVariables( query:String ) : Array {
var vars:URLVariables = new URLVariables (query);
var arr:Array = [];
for (var key : String in vars) {
var splitIndex : int = key.search(/[0-9]+$/);
var name:String = key.substr (0,splitIndex);
var indexNumber:int = parseInt ( key.substr(splitIndex));
arr[indexNumber] ||= {};
arr[indexNumber][name] = vars[key];
}
return arr;
}
Since your query string starts with a an ampersand, you might have to use parseURLVariables ( myString.substr(1)), otherwise the URLVariables object will throw an error, complaining that the query string is not valid (it has to be url encoded, and start with a variable key).
you may use split method of string to something like this;
var astrKeyValue: Array = url.Split( "&" );
in this way each value in astrKeyValue is string keyvalue ( for example font1=Arial )
after than you may split each item with "=" and will get pair key and value ( for key - font1 and for value - arial)
so this code maybe will work for you
var str = "text0=Enter Text...&size0=18&font0=Arial&color0=0&rotation0=0&y0=360&x0=640&text1=Enter Text...&size1=18&font1=Arial&color1=0&rotation1=0&y1=360&x1=640"
var a : Array = str.split( "&" );
var newArr: Array = new Array()
for each ( var str1 in a )
{
var t: Array = str1.split( "=" );
newArr[ t[0] ] = t[1];
}
trace( newArr.text0 ) // -> Enter Text...
Here is a solution for you from me,
//your string data should be like this, there should be a seperate seperator (i've used pipe sign |) for each element which will be converted to an object and then pushed to the array
var strData:String = "text=Enter Text...&size=18&font=Arial&color=0&rotation=0&y=360&x=640|text=Enter Text...&size=18&font=Arial&color=0&rotation=0&y=360&x=640";
var myArray:Array = new Array();
var _tmpArr:Array = strData.split("|");
//populating the array
for(var i:int=0;i<_tmpArr.length;i++)
{
myArray.push(strToObj(_tmpArr[i]));
}
trace(myArray.length);
// coverts chunk of string to object with all key and value in it
function strToObj(str:String):Object
{
var obj:Object = new Object();
var tmpArr:Array = str.split('&');
for (var i:int = 0; i < tmpArr.length; i++)
{
var _arr:Array = String(tmpArr[i]).split('=');
var key:String = String(_arr[0]);
var val:String = String(_arr[1]);
obj[key] = val;
trace(key+" = "+val);
}
trace("----");
return obj;
}
I need to change the contents of a cell on google spreadsheets.
I have successfully gotten the data via google docs api (all required authorization and options tag are set).
But I can't change the cell content. I have generated the following url and data:
req url: https://spreadsheets.google.com/feeds/cells/0AnT0uFQJWw_edENkYndfQWxCWlVmeG9oNW5kWjhYVUE/tCdbw_AlBZUfxoh5ndZ8XUA/private/full/R2C1
req data: <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:gs='http://schemas.google.com/spreadsheets/2006'><id>https://spreadsheets.google.com/feeds/cells/0AnT0uFQJWw_edENkYndfQWxCWlVmeG9oNW5kWjhYVUE/tCdbw_AlBZUfxoh5ndZ8XUA/private/full/R2C1</id><link rel='edit' type='application/atom+xml' href='https://spreadsheets.google.com/feeds/cells/0AnT0uFQJWw_edENkYndfQWxCWlVmeG9oNW5kWjhYVUE/tCdbw_AlBZUfxoh5ndZ8XUA/private/full/R2C1'/><gs:cell row='2' col='1' inputValue='*match found*
имя: вася
фамилия: тра та та
номер телефона дом: +7123456789
номер телефона моб: +7098765432
город: москва'/></entry>
repl data: Response contains no content type
And sometimes I recieve "bad request" in reply.
i following this document when writing code, and create this:
1. i getting cellsfeed url
NETLIBHTTPREQUEST nlhr = {0};
nlhr.cbSize = sizeof(NETLIBHTTPREQUEST);
nlhr.headersCount = 2;
nlhr.headers = (NETLIBHTTPHEADER*)malloc(sizeof(NETLIBHTTPHEADER) * (nlhr.headersCount));
nlhr.headers[0].szName = "Authorization";
if(AuthTag.empty())
{
string str;
str += "GoogleLogin auth=";
str += Auth;
AuthTag = str;
nlhr.headers[0].szValue = _strdup(str.c_str());
}
else
nlhr.headers[0].szValue = _strdup(AuthTag.c_str());
nlhr.headers[1].szName = "GData-Version";
nlhr.headers[1].szValue = "3.0";
nlhr.cbSize = sizeof(NETLIBHTTPREQUEST);
nlhr.flags = NLHRF_SSL;
{
string str = "https://spreadsheets.google.com/feeds/worksheets/";
str += toUTF8(Params.vtszDocuments[0]);
str += "/private/full";
nlhr.szUrl = _strdup(str.c_str());
}
nlhr.requestType = REQUEST_GET;
nlhr2 = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&nlhr);
if(!nlhr2)
{
boost::this_thread::sleep(boost::posix_time::minutes(Params.Interval));
continue;
}
using namespace rapidxml;
xml_document<> xml;
xml.parse<0>(nlhr2->pData);
Netlib_CloseHandle(nlhr2);
for(xml_node<> *node = xml.first_node()->first_node("entry"); node; node = node->next_sibling("entry"))
{
if(strcmp(node->first_node("title")->value(), toUTF8(Params.tszListName).c_str()))
continue;
bool found = false;
xml_node<> *id = node->first_node("id");
string spreadshit_id = id->value();
if(spreadshit_id.find(toUTF8(Params.vtszDocuments[0])) == string::npos)
continue;
for(xml_node<> *link = node->first_node("link"); link; link = link->next_sibling("link"))
{
if(strcmp(link->first_attribute("rel")->value(), "http://schemas.google.com/spreadsheets/2006#cellsfeed"))
continue;
cellsfeed = link->first_attribute("href")->value();
found = true;
if(found)
break;
}
if(found)
break;
}
2. i getting cellsfeed to buffer for parsing on need
base_document_xml.clear();
if(base_document_xml_buffer)
free(base_document_xml_buffer);
NETLIBHTTPREQUEST nlhr = {0};
nlhr.cbSize = sizeof(NETLIBHTTPREQUEST);
nlhr.headersCount = 2;
nlhr.headers = (NETLIBHTTPHEADER*)malloc(sizeof(NETLIBHTTPHEADER) * (nlhr.headersCount));
nlhr.headers[0].szName = "Authorization";
if(AuthTag.empty())
{
string str;
str += "GoogleLogin auth=";
str += Auth;
AuthTag = str;
nlhr.headers[0].szValue = _strdup(str.c_str());
}
else
nlhr.headers[0].szValue = _strdup(AuthTag.c_str());
nlhr.headers[1].szName = "GData-Version";
nlhr.headers[1].szValue = "3.0";
nlhr.cbSize = sizeof(NETLIBHTTPREQUEST);
nlhr.flags = NLHRF_SSL;
nlhr.szUrl = _strdup(cellsfeed.c_str());
nlhr.requestType = REQUEST_GET;
nlhr2 = (NETLIBHTTPREQUEST*)CallService(MS_NETLIB_HTTPTRANSACTION, (WPARAM)hNetlibUser, (LPARAM)&nlhr);
if(!nlhr2)
{
boost::this_thread::sleep(boost::posix_time::minutes(Params.Interval));
continue;
}
using namespace rapidxml;
base_document_xml_buffer = _strdup(nlhr2->pData);
base_document_xml.parse<0>(base_document_xml_buffer); //memory leak ?
Netlib_CloseHandle(nlhr2);
3. i getting etag and edit url for needed cell
string edit_link, etag;
using namespace rapidxml;
for(xml_node<> *node = base_document_xml.first_node()->first_node("entry"); node; node = node->next_sibling("entry"))
{
xml_node<> *cell_id = node->first_node("gs:cell");
char buf[4];
_itoa(i->row +1 ,buf, 10);
if(strcmp(cell_id->first_attribute("row")->value(), buf))
continue;
_itoa(i->column +1 ,buf, 10);
if(strcmp(cell_id->first_attribute("col")->value(), buf))
continue;
for(xml_node<> *link = node->first_node("link"); link; link = link->next_sibling("link"))
{
if(strcmp(link->first_attribute("rel")->value() , "edit"))
continue;
edit_link = link->first_attribute("href")->value();
etag = node->first_attribute("gd:etag")->value();
}
}
i using Miranda IM core network library in this code, and i think all right with network part, something wrong with request url or data content in request
UPD:
i have missed content type header in first code, now i fixed this, but have another problem, google returning "premature end of file"..., code updated.
UPD2:
i have solve this problem, it caused by wrong parameters passed by netowrk library, now i have following Invalid query parameter value for grid-id., and does not understand what it means...
UPD3:
looks like i have misunderstand api, i need to rewrite some code, i will post result here...
UPD4:
i have tried to obtain edit url via different api function, but have same result ...
UPD5:
i have solved this problem, not optimal and i thnk slow way, but at least working, i implement few more api calls and addition xml parsing steps to get correct link for edit each cell, code updated if someone need this, rapidxml parsing library and miranda im core net library used here.
I am able to retrieve database values and insert database values, but I can't figure out what the Update() syntax should be with a where statement.
Environment -> ASP.Net, C#
Settings.ttinclude
const string Namespace = "subsonic_db.Data";
const string ConnectionStringName = "subsonic_dbConnectionString";
//This is the name of your database and is used in naming
//the repository. By default we set it to the connection string name
const string DatabaseName = "subsonic_db";
Retreive example
var product = equipment.SingleOrDefault(x => x.id == 1);
Insert Example
equipment my_equipment = new equipment();
try
{
// insert
my_equipment.parent_id = 0;
my_equipment.primary_id = 0;
my_equipment.product_code = product_code.Text;
my_equipment.product_description = product_description.Text;
my_equipment.product_type_id = Convert.ToInt32(product_type_id.SelectedItem.Value);
my_equipment.created_date = DateTime.Now;
my_equipment.serial_number = serial_number.Text;
my_equipment.Save();
}
catch (Exception err)
{
lblError.Text = err.Message;
}
Edit: Think that I was just too tired last night, it is pretty easy to update. Just use the retrieve function and use the Update() on that.
var equip = Equipment.SingleOrDefault(x => x.id == 1);
lblGeneral.Text = equip.product_description;
equip.product_description = "Test";
equip.Update();
Resolved. View answer above.